I added a new class to my project and got an error saying “Program.Main() has more than one entry”. Why?

后端 未结 9 2304
萌比男神i
萌比男神i 2020-12-06 00:19

The problem is that after I added the new class, the error came up when I did build the solution. What can be wrong?

In Form1, I don’t have any code yet.

I jus

9条回答
  •  时光说笑
    2020-12-06 01:01

    A .NET program should have only one static Main method.

    You have two, and the compiler doesn't know which one to use.

    Rename the pasted one, unless you want it to be the entry point to the application (in which case, rename the other), or compile the application passing using the /main switch specifying which of the Main methods to use.

    See Main() and Command-Line Arguments (C# Programming Guide) on MSDN for more detail:

    The Main method is the entry point of a C# console application or windows application. (Libraries and services do not require a Main method as an entry point.). When the application is started, the Main method is the first method that is invoked.

    There can only be one entry point in a C# program. If you have more than one class that has a Main method, you must compile your program with the /main compiler option to specify which Main method to use as the entry point. For more information, see /main (C# Compiler Options).

    (emphasis mine)

提交回复
热议问题