Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (37 sloc) 1.8 KB
title f1_keywords helpviewer_keywords ms.assetid
-main (C# Compiler Options)
-main compiler option [C#]
main compiler option [C#]
/main compiler option [C#]

-main (C# Compiler Options)

This option specifies the class that contains the entry point to the program, if more than one class contains a Main method.




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. For 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.


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.

This option is for use when compiling an .exe file.

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.

    To set this compiler option programmatically, see xref:VSLangProj80.ProjectProperties3.StartupObject%2A.


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

You can’t perform that action at this time.