Strings are nothing but the set of characters or the literal constant. Sometime we define strings as a variable too.
a string is represented between set of double quotes.
There are two methods for building strings in C#
- Using Operators
- Using Strings
Method 1
In this method we do use '+' mathematical operator for building a string.
This methods works as
"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
Method 2
In this method we do use string keyword and its functioning.
String.Format() is used to format strings for display to the user.
This method works as
String.Format("There are {0} secs in a year", i);
// for single variable
String.Format("There are {0} secs, {1} mins in a year", i, j);