The string keyword is an alias for the System.String class. The String class has the following two properties −
| Sr.No. | Property & Description |
|---|---|
| 1 | Chars Gets the Char object at a specified position in the current Stringobject. |
| 2 | Length Gets the number of characters in the current String object. |
The following are some of the methods of String class −
| Sr.No. | Methods & Description |
|---|---|
| 1 | public static int Compare(string strA, string strB) Compares two specified string objects and returns an integer that indicates their relative position in the sort order. |
| 2 | public static int Compare(string strA, string strB, bool ignoreCase ) Compares two specified string objects and returns an integer that indicates their relative position in the sort order. However, it ignores case if the Boolean parameter is true. |
| 3 | public static string Concat(string str0, string str1) Concatenates two string objects. |
| 4 | public static string Concat(string str0, string str1, string str2) Concatenates three string objects. |
| 5 | public static string Concat(string str0, string str1, string str2, string str3) Concatenates four string objects. |
Let us see how to create a string and join a string in the following example −
Example
using System;
namespace StringApplication {
class StringProg {
static void Main(string[] args) {
string[] starray = new string[]{"Cricket is my life",
"It is played between two teams",
"It has three formats",
"T20, Test Cricket and ODI",
"Cricket is life"
};
string str = String.Join("\n", starray);
Console.WriteLine(str);
}
}
}