What is “string[] args” in Main class for?

后端 未结 8 1497
眼角桃花
眼角桃花 2020-12-13 01:37

In C# the Main class has string[] args parameter.

What is that for and where does it get used?

相关标签:
8条回答
  • 2020-12-13 02:27

    It's an array of the parameters/arguments (hence args) that you send to the program. For example ping 172.16.0.1 -t -4

    These arguments are passed to the program as an array of strings.

    string[] args // Array of Strings containing arguments.

    0 讨论(0)
  • 2020-12-13 02:28

    Further to everyone else's answer, you should note that the parameters are optional in C# if your application does not use command line arguments.

    This code is perfectly valid:

    internal static Program
    {
        private static void Main()
        {
            // Get on with it, without any arguments...
        }
    }
    
    0 讨论(0)
提交回复
热议问题