The source code to demonstrate the command line arguments is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//Program to demonstrate the command line arguments.
using System;
class Demo
{
static void Main(string[] args)
{
Console.WriteLine("Command Line Arguments:");
foreach (string arg in args)
{
Console.WriteLine("\t"+arg);
}
}
}
Compilation:
csc test.cs
Execute:
test.exe India Pak China
Output:
Command Line Arguments:
India
Pak
China
Explanation:
In the above program, we created a class Demo that contains the Main() method. The Main() method is the entry point for the program. Here we accessed the command line arguments and print them on the console screen. To pass command line arguments, we need to compile and run the program from the command line.
Program:
The source code to demonstrate the command line arguments is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Compilation:
Execute:
Output:
Explanation:
In the above program, we created a class Demo that contains the Main() method. The Main() method is the entry point for the program. Here we accessed the command line arguments and print them on the console screen. To pass command line arguments, we need to compile and run the program from the command line.