Chapter 6. Framework Fundamentals
Many of the core facilities that you need when programming are provided not by the C# language, but by types in .NET Core. In this chapter, we cover types that help with fundamental programming tasks, such as virtual equality comparison, order comparison, and type conversion. We also cover the basic .NET types, such as string, DateTime, and Enum.
The types in this section reside in the System namespace, with the following exceptions:
StringBuilderis defined inSystem.Text, as are the types for text encodings.CultureInfoand associated types are defined inSystem.Globalization.XmlConvertis defined inSystem.Xml.
String and Text Handling
char
A C# char represents a single Unicode character and aliases the System.Char struct. In Chapter 2, we described how to express char literals:
char c = 'A'; char newLine = '\n';
System.Char defines a range of static methods for working with characters, such as ToUpper, ToLower, and IsWhiteSpace. You can call these through either the System.Char type or its char alias:
Console.WriteLine (System.Char.ToUpper ('c')); // C
Console.WriteLine (char.IsWhiteSpace ('\t')); // True
ToUpper and ToLower honor the end user’s locale, which can lead to subtle bugs. The following expression evaluates to false in Turkey:
char.ToUpper ('i') == 'I'
The reason is that, in Turkey, char.ToUpper ('i') is 'İ' (notice the dot on top!). To avoid this problem, System.Char (and System.String) also provides culture-invariant ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access