C# Command Line Arguments

In C#, Arguments to the main method can be sent by command line. Those arguments are called command line arguments. The string[] args variable holds the command line arguments Let's see a simple example of passing arguments from command line.

using System;
public class CommandLineExample
{
            public static void Main (string[] args)
            {
                        Console.WriteLine("Arguments Lengths"+args.Length);
                        foreach(object i in args)
                        {
                                    Console.WriteLine(i);
                        }
            }
}
Note:
Compile the program as: CSC Program.cs
Run the Program as: Program.exe 1 2 3 4 5



ADVERTISEMENT
ADVERTISEMENT