C# - Environment.CommandLine Property with Example

In this tutorial, we will learn about the C# Environment.CommandLine property with its definition, usage, syntax, and example. By Nidhi Last updated : March 30, 2023

Environment.CommandLine Property

The Environment.CommandLine property returns a string value that contains command-line arguments.

Syntax

string Environment.CommandLine

Parameter(s)

  • None

Return Value

This property returns 'string' value.

C# Example of Environment.CommandLine Property

The source code to get and print the command line arguments using Environment class is given below. The given program is compiled and executed successfully.

using System;

class Sample
{
    //Entry point of Program
    static public void Main()
    {
        string cmdLine = "";

        cmdLine = Environment.CommandLine;
        Console.WriteLine("Command Line: \n"+cmdLine);
    }
}

Here, we will execute the program using the command prompt. Then we will print the command line argument using the program.

Output

D:\>Program.exe ABC 123
Command Line:
Program.exe  ABC 123

C# Environment Class Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.