Common uses of string
In order to obtain a writable char array, you can use the ToCharArray () command of the array variable
String myString = "A String"; char[] Mychars = Mystring.tochararray ();
You can also use strings in a foreach loop
foreach (char character in myString) { Console.WriteLine ("{0}", character);}
<string>. ToLower () and <string>. ToUpper () to convert the string to association or uppercase, respectively. This command creates a new string to compare with another string, or to assign another variable.
Delete the space in the input character, <string>. Trim ()
You can also use these commands to remove other characters, as long as you specify the characters in a char array
1 Char [] TrimChars = {'e's'}; 2 string trimstring = Mystring.trim (trimChars);
<string>. TrimStart () <sting>. The TrimEnd () command allows them to delete a space before or after a string. You can also specify a char array when using these commands.
<string>. PadLeft () <string>. PadRight (), add a space to the left or right of the string to make the string reach the specified length.
1 " Aligned " ; 2 myString = Mystring.padleft (ten); 3 myString = Mystring.padleft ('-');
<string>. Split () converts the sstring to a string array, separating him from the specified position, in the form of a char array
1 char[] separator = {' }; 2 string mywords; 3 mywords = mystring.split (separator);
- Static constructors and static classes
When you use static members in a class, you need to initialize those members beforehand. At the time of declaration, you can provide a static member with an initial value, but sometimes you need to perform more complex initialization or perform some action before copying or executing a static method.
You can perform this type of initialization task using a static constructor. A class can have only one static constructor, which cannot have an access modifier or take any parameters. Static constructors cannot be called directly and can only be performed in the following cases:
1. When you create a class instance that contains a static constructor
2. When accessing static members of a class that contains static constructors
In both cases, the static constructor is called first, and then the class is instantiated or the static member is accessed. No matter how many instances of a class are created, their static constructors are called only once.
Static class functions contain static members and cannot contain instance constructors.
C # Getting Started-reading notes