Note:
This is Java's System.getProperties() equivalent in C#. See
Show_Properties
on the blog
Thinking_in_Java,
Chapter_3.
ShowProperties.cs
public class ShowProperties
{
public static void Main()
{
System.Reflection.PropertyInfo[] myPropertyInfo;
// Get the properties of 'System.Environment' class object:
myPropertyInfo = System.Type.GetType("System.Environment").GetProperties();
System.Console.WriteLine("Properties of System.Environment are:");
for (int i = 0; i < myPropertyInfo.Length; i++)
{
System.Console.WriteLine(myPropertyInfo[i].ToString());
}
System.Console.WriteLine();
System.Console.WriteLine("CommandLine: {0}",
System.Environment.CommandLine);
System.Console.WriteLine("CurrentDirectory: {0}",
System.Environment.CurrentDirectory);
System.Console.WriteLine("ExitCode: {0}", System.Environment.ExitCode);
System.Console.WriteLine("HasShutdownStarted: {0}",
System.Environment.HasShutdownStarted);
System.Console.WriteLine("MachineName: {0}",
System.Environment.MachineName);
System.Console.WriteLine("OSVersion: {0}",
System.Environment.OSVersion.ToString());
System.Console.WriteLine("SystemDirectory: {0}",
System.Environment.SystemDirectory);
System.Console.WriteLine("TickCount: {0}",System.Environment.TickCount);
System.Console.WriteLine("UserDomainName: {0}",
System.Environment.UserDomainName);
System.Console.WriteLine("UserName: {0}", System.Environment.UserName);
System.Console.WriteLine("Version: {0}", System.Environment.Version.ToString());
System.Console.WriteLine("WorkingSet: {0}", System.Environment.WorkingSet);
System.Console.WriteLine("SystemPageSize: {0}",
System.Environment.SystemPageSize);
System.Console.WriteLine("Is64BitProcess: {0}",
System.Environment.Is64BitProcess);
System.Console.WriteLine("ProcessorCount: {0}",
System.Environment.ProcessorCount);
System.Console.WriteLine();
string query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";
string str = System.Environment.ExpandEnvironmentVariables(query);
string nl = System.Environment.NewLine;
System.Console.WriteLine("ExpandEnvironmentVariables: {0} {1}", nl, str);
System.Console.WriteLine("GetEnvironmentVariable: {0} My temporary directory is {1}.",
nl, System.Environment.GetEnvironmentVariable("TEMP"));
System.Console.WriteLine("GetEnvironmentVariables: ");
System.Collections.IDictionary environmentVariables =
System.Environment.GetEnvironmentVariables();
foreach (System.Collections.DictionaryEntry de in environmentVariables)
{
System.Console.WriteLine(" {0} = {1}", de.Key, de.Value);
}
System.Console.WriteLine("GetFolderPath: {0}",
System.Environment.GetFolderPath(System.Environment.SpecialFolder.System));
string[] drives = System.Environment.GetLogicalDrives();
System.Console.WriteLine("GetLogicalDrives: {0}", System.String.Join(", ", drives));
}
}
/*
mcs ShowProperties.cs
mono ShowProperties.exe
*/
Comments
Post a Comment