C# Command Line Argument

We all understand, that we can pass parameter to a function as argument but what about Main(string[] args) method? Do parameters can be passed to Main() method in C#? Yes, parameter(s) can be passed to a Main() method in C# and it is called command line argument.

Main() method is where program stars execution. Main method doesn’t accept parameter from any method. It accept parameter through command line. It is an array type parameter that can accept n number of parameter in runtime.

In Main(string[] args) , args is a string type of array that can hold numerous parameter.

To understand command line argument in C#, think about the following instruction example.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Command_Line_Parameter
    class Program
        static void Main(string[] args)
            Console.WriteLine("First Name is " + args[0]);
            Console.WriteLine("Last Name is " + args[1]);

Leave a Reply

Your email address will not be published. Required fields are marked *