Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

C# Program to Get and Print the Command Line Arguments Using Environment Class

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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.



Return Type: The return type of this property is a string. This string represents the command-line arguments.


Input  : Hello Geeks
Output : Hello Geeks

Input  : Hello 123
Output : Hello 123


// 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"


E:\> example.exe Hello Geeks
Command Line Data:
example.exe Hello Geeks
My Personal Notes arrow_drop_up
Last Updated : 01 Nov, 2021
Like Article
Save Article
Similar Reads
Related Tutorials