有如下简单的console程序
1 using System; 2 3 namespace HelloWorld 4 { 5 class Program 6 { 7 static void Main(string[] args) 8 { 9 Console.WriteLine("Main from Program");10 }11 }12 }
编译,运行:
C:\Users\yshuangj\Desktop\HelloWorld>csc Program.csMicrosoft (R) Visual C# 2005 Compiler version 8.00.50727.8745for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.C:\Users\yshuangj\Desktop\HelloWorld>Program.exeMain from Program
也可以指定入口Main函数,再编译,运行
1 C:\Users\yshuangj\Desktop\HelloWorld>csc Program.cs /main:HelloWorld.Program2 Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.87453 for Microsoft (R) Windows (R) 2005 Framework version 2.0.507274 Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.5 6 7 C:\Users\yshuangj\Desktop\HelloWorld>Program.exe8 Main from Program
这样做的目的是,在编译时,指定哪个Main函数作为入口函数,因为除Program类外,其它类也可能有一个Main函数。