C# Programming > Miscellaneous

C# Environment Properties

System Properties

Determening system properties in C# can be easy. System properties are any information that pertains to the operating system in which the application is running.

No complicated source code will be necessary.

Environment

The .NET Framework includes a static class called Environment which is under the System namespace. As expected, Environment contains properties and static methods that give the application information about its environment, which is operating system, which will usually be Windows. Since the methods are static developers can call them without initializing the class (in fact because it is a static class you can't create an instance of it).

Examples

There is nothing much to it, the only thing left is to play around with the environment properties and methods. So here are some examples.

Environment.OSVersion gives information about the version of the operation system, including major and minor versions and service packs. Environment.OSVersion.Version in Vista is 6. Environment.OSVersion.ServicePack would give "Service Pack 1" (depending on the operating system installed of course).

Environment.UserName gives the name of the current user logged in.

Environment.GetFolderPath(Environment.SpecialFolder.Desktop) returns the path of the Desktop (based on the current user logged in) as a string. Environment.SpecialFolder contains references to other folders such as Cookies, MyDocuments, Favorites, History, ProgramFiles, and many more.

Just like that there are many other environment variables that can be accessed in C# through the Environment static class.

Back to C# Article List