C# Program to Get and Print the Command Line Arguments Using Environment Class
In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that it retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information, and time since the last system boot in milliseconds information. By just using some predefined methods we can get the information of the Operating System using the Environment class. In this article, we will discuss how to get and display the command line arguments using the Environment class. So to do this task we use the CommandLine property of the Environment Class. This property is used to find the command line for the current process.
Syntax:
Environment.CommandLine
Return Type: The return type of this property is a string. This string represents the command-line arguments.
Example:
Input : Hello Geeks Output : Hello Geeks Input : Hello 123 Output : Hello 123
C#
// C# program to display the command line arguments // using Environment Class using System; class GFG{ static public void Main() { // Declaring a string variable string commandlineResult = "" ; // Getting the command line argument // Using the CommandLine property of // Environment class commandlineResult = Environment.CommandLine; // Display the data Console.WriteLine( "Command Line Data: \n" + commandlineResult); } } |
Output:
E:\> example.exe Hello Geeks Command Line Data: example.exe Hello Geeks
Please Login to comment...