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

后端 未结 8 1519
眼角桃花
眼角桃花 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:14

    You must have seen some application that run from the commandline and let you to pass them arguments. If you write one such app in C#, the array args serves as the collection of the said arguments.

    This how you process them:

    static void Main(string[] args) {
        foreach (string arg in args) {
           //Do something with each argument
        }
    }
    

提交回复
热议问题