Main方法是C#控制台应用程序和Windows窗体应用程序的入口点。Main方法可以有形参,也可以没有,可以有返回值(int整型),也可以没有
static void Main()
static void Main(string[] args)
static int Main()
static int Main(string[] args)
对于参数string[] args的设置方式一:
测试代码:
static void Main(string[] args)
{
Console.WriteLine ("{0} command line arguments were specified", args.Length);
foreach (string arg in args)
{
Console.WriteLine(arg);
}
Console.ReadLine();
}
输出结果
方式二:
在开始菜单中打开“Visual Studio开发人员命令提示”窗口,
切换路径到cs文件所在目录。
用csc命令编译包含Main方法的cs文件,如:csc Program.cs。
编译成功后,当前目录下会生成一个Program.exe应用程序,这时可用Program param1 param2命令调用应用程序并执行应用程序,
每个参数之间用空格隔开,如果参数中有空格,就用双引号将该参数围着,这样应用程序就会将它识别为一个参数,而不是多个。
运行命令如下: