Multiple Main In C Sharp

Open the notepad editor and type the following code.
I saved my program on the path :- C:\Users\seven\Desktop\MainClass.cs

---------------------------------------------------------------------------------------------
using System;


class MultipleMainProg
{
public static void Main()
{
Console.WriteLine("I am in main function");
}
}


class MainClass
{
public static void Main()
{
Console.WriteLine("I am actually executing main function");


MultipleMainProg .Main();

}
}


-----------------------------------------------------------------------------------------------------------


For run this program, go to the

Start -> All Programs -> Microsoft Visual Studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt 2010.



if you compile this program like :- csc MainClass.cs then you get an error.


Now when you run your program on the command prompt you get an error like that





so to remove an error you should specify whose main function you want to execute first because the compiler confuse which main function is executed first and the other one on later.

so you should compile this program with the "/main" switch



Now you get how to run multiple main in C Sharp

Multiple Main In C Sharp Multiple Main In C Sharp Reviewed by Baljeet Singh on 00:23 Rating: 5

No comments:

Powered by Blogger.