Console app arguments, how arguments are passed to Main method

前端 未结 10 1200
醉话见心
醉话见心 2020-12-08 09:30

This would be question from c# beginner. When I create console application I get Main method with parameter args as array string. I do not understand how t

10条回答
  •  情书的邮戳
    2020-12-08 10:24

    Read MSDN.

    it also contains a link to the args.

    short answer: no, the main does not get override. when visual studio (actually the compiler) builds your exe it must declare a starting point for the assmebly, that point is the main function.

    if you meant how to literary pass args then you can either run you're app from the command line with them (e.g. appname.exe param1 param2) or in the project setup, enter them (in the command line arguments in the Debug tab)

    in the main you will need to read those args for example:

    for (int i = 0; i < args.Length; i++)
    {
        string flag = args.GetValue(i).ToString();
        if (flag == "bla") 
        {
            Bla();
        }
    }
    

提交回复
热议问题