Dark Mode
Image

C# Properties

C# Inheritance

C# Polymorphism

C# Strings

C# Generics

C# Delegates

C# Reflection

Anonymous Function

C# Multithreading

C# Synchronization

C# Web Service

C# Misc

C# New Features

C# Programs

ADO.NET Tutorial

ASP.NET Tutorial

C# Command Line Arguments

C# Command Line Arguments

Arguments that are passed by command line known as command line arguments. We can send arguments to the Main method while executing the code. The string args variable contains all the values passed from the command line.

In the following example, we are passing command line arguments during execution of program.

C# Command Line Arguments Example

using System; 

namespace CSharpProgram 

    class Program 

    { 

        // Main function, execution entry point of the program 

        static void Main(string[] args) // string type parameters 

        { 

            // Command line arguments 

            Console.WriteLine("Argument length: "+args.Length); 

            Console.WriteLine("Supplied Arguments are:"); 

            foreach (Object obj in args) 

            { 

                Console.WriteLine(obj);      

            } 

        } 

    } 

 

Compile and execute this program by using following commands.

Compile: csc Program.cs

Execute: Program.exe Hi there, how are you?

After executing the code, it produces the following output to the console.

Output:

Argument length: 5
Supplied Arguments are:
Hi
there,
how
are
you?

 

Comment / Reply From