Home »
.Net »
C# Programs
C# - Command Line Arguments Example
Here, we will learn about the command line arguments in C# with the help of example.
Submitted by Nidhi, on November 08, 2020 [Last updated : March 23, 2023]
Here, we will demonstrate the example of command line arguments and then print them on the console screen.
C# program to demonstrate the example of command line arguments
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.
C# Basic Programs »