by Dinesh Thakur Category: Introduction to C#

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:\> csc/main : first multiple.cs


This is First class

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.