CHAPTER 3 CORE C# PROGRAMMING CONSTRUCTS, PART I
}
Console.WriteLine("Value of biggy is {0}", biggy);
Console.WriteLine("Is biggy an even value?: {0}", biggy.IsEven);
Console.WriteLine("Is biggy a power of two?: {0}", biggy.IsPowerOfTwo);
BigInteger reallyBig = BigInteger.Multiply(biggy,
BigInteger.Parse("8888888888888888888888888888888888888888888"));
Console.WriteLine("Value of reallyBig is {0}", reallyBig);
It is also important to note that the BigInteger data type responds to C#’s intrinsic mathematical
operators, such as +, -, and *. Therefore, rather than calling BigInteger.Multiply() to multiply two huge
numbers, you could author the following code:
BigInteger reallyBig2 = biggy * reallyBig;
At this point, I hope you understand that the C# keywords representing basic data types have a
corresponding type in the .NET base class libraries, each of which exposes a fixed functionality. While I
have not detailed each member of these data types, you are in a great position to dig into the details as
you see fit. Be sure to consult the .NET Framework 4.5 SDK documentation for full details regarding the
various .NET data types—you will likely be surprised at the amount of built in functionality.
Source Code The BasicDataTypes project is located under the Chapter 3 subdirectory.
Working with String Data
System.String provides a number of methods you would expect from such a utility class, including
methods that return the length of the character data, find substrings within the current string, and
convert to and from uppercase/lowercase. Table 3-5 lists some (but by no means all) of the interesting
members.
Table 3-5. Select Members of System.String
String Member
Meaning in Life
Length
This property returns the length of the current string.
Compare()
This static method compares two strings.
Contains()
This method determines whether a string contains a specific substring.
Equals()
This method tests whether two string objects contain identical character
data.
Format()
This static method formats a string using other primitives (e.g., numerical
data, other strings) and the {0} notation examined earlier in this chapter.
Insert()
This method inserts a string within a given string.
95