CHAPTER 3 CORE C# PROGRAMMING CONSTRUCTS, PART I
}
bool b = bool.Parse("True");
Console.WriteLine("Value of b: {0}",
double d = double.Parse("99.884");
Console.WriteLine("Value of d: {0}",
int i = int.Parse("8");
Console.WriteLine("Value of i: {0}",
char c = Char.Parse("w");
Console.WriteLine("Value of c: {0}",
Console.WriteLine();
b);
d);
i);
c);
System.DateTime and System.TimeSpan
The System namespace defines a few useful data types for which there are no C# keywords, such as the
DateTime and TimeSpan structures (I’ll leave the investigation of System.Guid and System.Void, as shown
in Figure 3-2, to interested readers; but do be aware that these two data types in the System namespace
are seldom useful in most applications).
The DateTime type contains data that represents a specific date (month, day, year) and time value,
both of which may be formatted in a variety of ways using the supplied members. The TimeSpan structure
allows you to easily define and transform units of time using various members.
static void UseDatesAndTimes()
{
Console.WriteLine("=> Dates and Times:");
// This constructor takes (year, month, day).
DateTime dt = new DateTime(2011, 10, 17);
// What day of the month is this?
Console.WriteLine("The day of {0} is {1}", dt.Date, dt.DayOfWeek);
// Month is now December