Q:

C# program to demonstrate the use of GetCommandLineArgs() method of Environment class

belongs to collection: C# Environment Class Programs

0

Syntax:

string [] Environment.GetCommandLineArgs();

Parameter(s):

This does not accept any parameter.

Return value:

This method returns an array of strings that contains arguments passed on the command line.

Exception(s):

  • System.NotSupportedException
  •  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate the use of GetCommandLineArgs() method of 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[] cmdArg;

        cmdArg = Environment.GetCommandLineArgs();

        Console.WriteLine("Command Line Arguments:");
        foreach (string arg in cmdArg)
        {
            Console.WriteLine("\t"+arg);
        }
    }
}

Here, we execute the above program using a command prompt to see all arguments passed on the command line.

Output:

D:\>Program.exe 123 ABCD
Command Line Arguments:
        Program.exe
        123
        ABCD

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Environment Class Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to demonstrate the use of FailFast() me... >>
<< C# program to demonstrate the use of Exit() method...