C# program to demonstrate the command line arguments

Here, we are going to learn how to demonstrate the command line arguments in C#?
Submitted by Nidhi, on November 08, 2020

Here, we will demonstrate the command line arguments and then print them on the console screen.

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.

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


ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.