编译Console程序时,可以指定Main入口函数

有如下简单的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.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.8745
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.


C:\Users\yshuangj\Desktop\HelloWorld>Program.exe
Main from Program

也可以指定入口Main函数,再编译,运行

1 C:\Users\yshuangj\Desktop\HelloWorld>csc Program.cs /main:HelloWorld.Program
2 Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.8745
3 for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
4 Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
5 
6 
7 C:\Users\yshuangj\Desktop\HelloWorld>Program.exe
8 Main from Program

这样做的目的是,在编译时,指定哪个Main函数作为入口函数,因为除Program类外,其它类也可能有一个Main函数。

 

posted @ 2017-12-05 20:03  双健  阅读(388)  评论(0编辑  收藏  举报