Why is only the main method without parameters considered as a “valid startup object” for a C # project?

I downloaded the zip source files containing a C # project with multiple input points / Basic methods. Since I wanted to mess around, I created another similar one in a new type / class

class MyExperiments { static void Main(String[] args) { // do something } } 

then I switched to project properties. Just switch the launch object to MyExperiments, huh? To my surprise, this was not the drop-down list. I rebuilt, made the method public, tried a lot of everything ... but to no avail. Finally, I edited the .csproj file manually in notepad, and then it worked. After a bit of work, I deleted the settings to do this

 static void Main() 

and now VS Project properties can “see” the launch object. So now I can select it using the drop-down list. Then I added the line [] back and it still worked.

It seems a little strange to me (because the most common form is the Main method with command line argument parameters from C / C ++ times). MSDN says that the drop-down list will contain valid startup objects if they exist in your project.

+4
source share
3 answers

Good thing you copied it, it's the capital "S" in Main(String[] args) . Obviously, VS uses some text matching, and it is case sensitive. As it should be.

+6
source

lol - this seems like an error in the IDE:

 static void Main(String[] args) {} 

not displayed but

 static void Main(String[] args) {} 

does!

+5
source

Update: Reply to Connect / bug feedback message,

Thanks for the feedback! It looks like the problem here is that the “String” parameter in the main method should be a completely lowercase “string” (and this seems to have been pointed to your postoverflow post). I see a proposal here to update the project. The properties page will be a little smarter about collecting the launch object, but given that there is a reasonable workaround, we are going to invest our resources to stabilize and improve the performance of VS2010. I will go ahead and resolve the error as "Wont Fix", but please reactivate the error if you have other questions / comments.

Thank you DJ Park C # IDE, Program Manager

So it looks like you will need to stay in the back of your mind for the moment - Gishu

0
source

Source: https://habr.com/ru/post/1286613/


All Articles