CHAPTER 3 CORE C# PROGRAMMING CONSTRUCTS, PART I
static void ShowEnvironmentDetails()
{
// Print out the drives on this machine,
// and other interesting details.
foreach (string drive in Environment.GetLogicalDrives())
Console.WriteLine("Drive: {0}", drive);
}
Console.WriteLine("OS: {0}", Environment.OSVersion);
Console.WriteLine("Number of processors: {0}",
Environment.ProcessorCount);
Console.WriteLine(".NET Version: {0}",
Environment.Version);
The following output shows a possible test run of invoking this method. Of course, if you did not
specify command-line arguments via the Visual Studio Debug tab, you will not find them printed to the
console.
***** My First C# App *****
Hello World!
Arg: -godmode
Arg: -arg1
Arg: /arg2
Drive: C:\
Drive: D:\
Drive: E:\
Drive: F:\
Drive: G:\
Drive: H:\
Drive: I:\
OS: Microsoft Windows NT 6.1.7601 Service Pack 1
Number of processors: 4
.NET Version: 4.0.30319.17020
The Environment type defines members other than those shown in the previous example. Table 3-1
documents some additional properties of interest; however, be sure to check out the .NET Framework
4.5 SDK documentation for full details.
80