Environment in C#
What the process knows about where it is running.
Console.WriteLine(Environment.MachineName);
Console.WriteLine(Environment.ProcessorCount);
Console.WriteLine(Environment.CurrentDirectory);
// environment variables, with a shrug for the missing ones
var home = Environment.GetEnvironmentVariable("HOME") ?? "(not set)";
Console.WriteLine(home);
var profile = Environment.GetFolderPath(
Environment.SpecialFolder.UserProfile);
Console.WriteLine(profile);
How it works
MachineName,ProcessorCountand the current directory, direct.GetEnvironmentVariablereturns null;??supplies the shrug.GetFolderPathresolves well-known folders portably.
Keywords and builtins used here
var
The run, in numbers
- Lines
- 11
- Characters to type
- 405
- Tokens
- 68
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 43 seconds.
Step 2 of 3 in Diagnostics & environment, step 14 of 17 in The .NET library.