How to run more than one main method in a single console application in .NET
C# cannot run more than one main method at a time in a single file. Main method is also the entry point to the application. But it is syntatically ok to define more than one main method in your application in a single namespace with different class name. So, we have to provide the entry point to be compiled before we can run the desired main method of our choice.
For example we have a single C# file with multiple class and main method like given below
Now to run the required class we need to select the desired class name in the properties section in the project.
So, at the startup object section we have to select the desired class name which will provide the entry point as the main method of the selected class.
And the compiler will run the selected class.
Using this method we don't have to create separate project to run different console program. Thus saving the time and the tedious process for creating separate project for simple console program.