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 the .NET Framework. In this chapter, we cover the Framework’s role in fundamental programming tasks, such as virtual equality comparison, order comparison, and type conversion. We also cover the basic Framework types, such as String, DateTime, and Enum.

The types in this section reside in the System namespace, with the following exceptions:

  • StringBuilder is defined in System.Text, as are the types for text encodings.

  • CultureInfo and associated types are defined in System.Globalization.

  • XmlConvert is defined in System.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. For example:

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

Most of char’s static methods are related to categorizing characters and are listed in Table 6-1.

Table 6-1. Static methods for categorizing characters

Static method

Characters included

Unicode categories included

IsLetter

A-Z, a-z, and letters of other alphabets

UpperCaseLetter

LowerCaseLetter

TitleCaseLetter

ModifierLetter

Get C# 3.0 in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.