static System.Environment class provides a range of useful properties:
Item | Properties |
---|---|
Files and folders | CurrentDirectory, SystemDirectory, CommandLine |
Computer and operating system | MachineName, ProcessorCount, OSVersion, NewLine |
User logon | UserName, UserInteractive, UserDomainName |
Diagnostics | TickCount, StackTrace, WorkingSet, Version |
You can obtain additional folders by calling GetFolderPath.
You can access OS environment variables with the following three methods: GetEnvironmentVariable,GetEnvironmentVariables, and SetEnvironmentVariable.
ExitCode property sets the return code.
FailFast method terminates a program immediately without performing cleanup.
using System; class MainClass//w w w.j a v a 2 s . co m { public static void Main(string[] args) { Console.WriteLine(Environment.CurrentDirectory); } }