. In. NET, Char indicates a Unicode value of 16. Char provides two public const fields MinValue ('\ 0', which is the same as' \ u0000) and MaxValue ('\ uffff ').
Char. GetUnicodeCategory (char instance) to return the unicode type of char. One of the System. Globalization. UnicodeCategory enumerations is returned.
The category of '\ 0' is Control, and all categories are as follows:
Console. WriteLine (Enum. GetNames (View Code
Of course, the enumeration contains Chinese characters. The following Chinese characters are directly displayed as Other Letter.
Char provides a series of static methods, IsControl IsLetter IsNumber, and so on. It calls GetUnicodeCategory internally. Because we cannot modify the. NET Assembly, we can add the extension method IsChineseCharacter to the char structure. Currently, the common Chinese matching range is, which can be determined by writing an extension method for Char.
IsChineseCharacter (low = high = Between <T> (T: IComparable <T> current. CompareTo (low) * current. CompareTo (high) <=}View Code
Converts the case of Char. invariant is fixed and unchanged. ToUpperInvariant converts case sensitivity in a way that ignores culture. ToUpper ToLower will. threading. thread. currentThread. currentCulture gets information about cultural areas
Conversion
1. forced type conversion: the compiler will generate IL commands to execute the conversion, which is the most efficient. You can also specify checkd and unchecked. For example, you can unchecked (char) (65535 + 65), uppercase
2. System. Convert class, a bunch of static methods, always converted in checked mode
3. IConvertible interface, which has the worst efficiency. To call an API method of the value type, you must pack it and forcibly convert it into an IConvertible interface for calling. The IConvertible interface is displayed for implementation.
String
1. Construct
String s = "Hello World! ";
String snew = new String ("Hello World! "); // This method is not allowed
In the IL command, newobj is used for new Object. For the string command ldstr, the string will be embedded into the Assembly metadata during compilation and loaded from the metadata.
For string s = "strpart1" + "" + "strpart2"; all such strings are [direct quantities], they will be concatenated into a string to embed metadata during compilation. strings are allocated on the hosting stack.
2. the string is immutable, and any changes to the string will not affect the original string (PS: encountered pitfalls when I was a beginner, various types of troubleshooting ...), returns the new string, which causes a lot of string garbage.
String reserved, internal hashtable, only one for the same string, such as String s1 = "hello", s2 = "hello"; s1 = string. intern (s1); s2 = String. intern (s2). At this time, the referenceEqual of s1 and s2 is true, that is, pointing to the same object... C # The Compiler does not need this anymore. The CLR via C # book also says this. If too many strings affect program efficiency, you can study it again.
3. String comparison
What are the methods and cultural characteristics?
Method equals compare startwith endwith, which contains a StringComparison comparisonType Parameter
StringComparison enumeration:
CurrentCulture InvariantCulture Oridinal and their IgnoreCase versions
Invariant: As mentioned earlier, the constant and fixed Culture means that there is no specific language or Culture.
Oridinal: sequential, sequential. It is called Serial Number comparison in the book, and the execution string is the fastest.
Summary: InVariant is not used when processing data displayed to users. Equal uses Oridinal by default, and CompareTo relies on Culture by default, non-Oridinal will expand the string (some letters in other languages are combined with a few letters and can only be compared.
CultureInfo
CurrentCulture: control currency, date, and so on
CurrentUICulture: controls the Culture of the UI Interface
CultureInfo references a SystemGlobalization. CompareInfo, which contains the Compare method.
View the source code of String. CompareTo. You can see that CompareInfo. Compare is called.
4. StringBuilder
In either case, a new object is allocated in the managed heap.
1. The constructed string exceeds the Capcity of StringBuilder.
2. Call ToString to continue Modification