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

后端 未结 9 2291
萌比男神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:02

    Others have pointed out that you have two static void Main methods. There are two easy fixes for this, one obvious and one that hasn't been specifically mentioned yet:

    1. Rename one to anything else e.g. Main1, NotMain, etc.
    2. To set the /main compiler option mentioned by Habib, just right click on the project node in Solution Explorer, select Properties, and in the Application section select the "Startup object" in the dropdown.

    With solution 2, you can have identical Main(string[] args) signatures in different classes without the compiler whining.

提交回复
热议问题