-main (C# 編譯器選項)-main (C# Compiler Options)

如果有多個類別包含 Main 方法,這個選項會指定含有程式進入點的類別。This option specifies the class that contains the entry point to the program, if more than one class contains a Main method.

語法Syntax

-main:class  

引數Arguments

class
含有 Main 方法的類型。The type that contains the Main method.
提供的類別名稱必須完整。名稱必須包括內含類別的完整命名空間,後面接著類別名稱。The provided class name must be fully qualified; it must include the full namespace containing the class, followed by the class name. 例如,當 Main 方法位於 MyApplication.Core 命名空間中的 Program 類別時,編譯器選項必須是 -main:MyApplication.Core.ProgramFor example, when the Main method is located inside the Program class in the MyApplication.Core namespace, the compiler option has to be -main:MyApplication.Core.Program.

備註Remarks

如果編譯的 Main 方法中包含一個以上的型別,您可以指定哪個型別含有要作為程式進入點的 Main 方法。If your compilation includes more than one type with a Main method, you can specify which type contains the Main method that you want to use as the entry point into the program.

在編譯 .exe 檔案時,即可使用此選項。This option is for use when compiling an .exe file.

在 Visual Studio 開發環境中設定這個編譯器選項To set this compiler option in the Visual Studio development environment

  1. 開啟專案的 [屬性] 頁面。Open the project's Properties page.

  2. 按一下 [應用程式] 屬性頁。Click the Application property page.

  3. 修改 [啟始物件] 屬性。Modify the Startup object property.

    若要以程式設計方式設定這個編譯器選項,請參閱 StartupObjectTo set this compiler option programmatically, see StartupObject.

範例Example

編譯 t2.cst3.cs,將 Main 方法的位置指定在 Test2 中:Compile t2.cs and t3.cs, specifying that the Main method will be found in Test2:

csc t2.cs t3.cs -main:Test2  

另請參閱See also