C# has a strong feature in which we can define more than one class with the Main method. Since Main is the entry point for the program execution, there are now more than one entry points. In fact, there should be only one entry point. Which will be resolved by specifying which Main is to be used to the compiler at the time of compilation as shown below:
csc filename.cs/main : class name
Where filename is the name of file where code is stored and classname is the name of class containing the Main which we would like to be the entry point. To understand the concept lets see an example.
Program with multiple Main Methods
using system;
class First {
public static void Main()
{
conso1e.writeLine(“This is First Class”); }
}
class second {
public static void Main() {
conso1e.writeLine(“This is second class”); }
}
c1ass Third {
public static void Main() {
conso1e.writeLine(“This 1S Third Class”); }
}
Compilation and Execution of Program
(suppose the name of file is multiple.cs)
c:\> csc/main : second mu1tiple.cs
c:\> multiple
This is second class
C:\>
C:\> csc/main : first multiple.cs
C:\>multiple
This is First class