Main()函数

Main函数是C#应用程序的入口点,执行Main()就是执行应用程序

Main函数有四种不同形式

1 static void Main()
2 static void Main(string[] args)
3 static int Main()
4 static int Main(string[] args)

args为命令行参数,可以在调试中添加和更改

int返回值一般情况下返回0代表“正常”的终止(即应用程序已经执行完毕,并安全终止)

 1 //在命令行中加入 256 myfile.txt"a long argument" 666
 2 /*
 3 空格代表分割,此处为3个元素
 4 若参数中包含空格则用""包括起来
 5 */
 6 Console.WriteLine($"{args.Length} command line arguments were specified:");
 7 foreach(string arg in args)
 8 {
 9     Console.WriteLine(arg);
10 }
11 Console.ReadKey();

猜你喜欢

转载自www.cnblogs.com/xt112233/p/9899027.html
今日推荐