Home > Article > Backend Development > Command line arguments in C#
If you want to pass parameters through command line then use command line parameters in C#-
When we create a program in C#, use static void main, We can see the parameters.
class HelloWorld { static void Main(string[] args) { /* my first program in C# */ Console.WriteLine("Hello World"); Console.ReadKey(); }
string[] args is a variable that contains all the values passed from the command line as shown above.
Now to print these parameters, suppose we have a parameter "One" -
Console.WriteLine("Length of the arguments: "+args.Length); Console.WriteLine("Arguments:"); foreach (Object obj in args) { Console.WriteLine(obj); }
The above will print -
Length of the arguments: 1 Arguments: One
The above is the detailed content of Command line arguments in C#. For more information, please follow other related articles on the PHP Chinese website!