Knowing Your Environment: the System.Environment Class
(Page 1 of 4 )
When developing applications (Windows or web), it is very important for the developer to know the environment in which the application is running. Having this information will help the developer customize the software and make the user experience more enjoyable. In this regard, .NET provides a class in the System namespace called Environment, which is the subject of this article.
The environment class contains methods and properties that provide information about the current environment and platform. It is important to note that this class cannot be inherited. In other words, you cannot extend the functionality in this class to create your own class.
Here is a rundown of some of the handy methods and properties that this class provides, with minor explanation on the usage of each.
Properties
CommandLine: The call to Environment.CommandLine will provide the full name of the application, followed by the command line arguments. The command line arguments are the pieces of data entered after the application name. For example:
Multiply.exe x1 x2
In this case, x1 and x2 are the command line arguments. In order to get access to x1 and x2, you use the args array passed to the Main method. Here is the method signature:
static void Main( string [] args)
Visual Studio provides two ways to enter the command line arguments:
By running the application from the command prompt.
By entering the arguments in the Debug tab of the project properties:

Here is a statement that shows how you access the CommandLine property:
//returns a string containing command-line arguments
Console .WriteLine( "The command line is: " + Environment .CommandLine);
Next: More Properties >>
More .NET Articles
More By Ayad Boudiab