Building Strings in C#
There are two methods for building strings in C#.
- Using Operators
- Using Strings
Method 1: In this method we use '+' mathematical operator for building a string.
This method works as the following:
"There are" + i + "secs in a year";
// for single variable
"There are" + i + "secs" + j + "mins in a year";
// for double variables
This method works for both:
- Javascript
- C#
Method 2: In this method we use the string keyword and its functioning. The String.Format() is used to format strings for display, for the user.
This method works as the following:
String.Format("There are {0} secs in a year", i);
// For a single variable
String.Format("There are {0} secs, {1} mins in a year", i, j);
// For double variables