What happens when a C# project has more than 1 Main methods

A) Compiler throws warning message
B) Compiler throws Error message
C) Compiler successfully compiles

Showing Answers 1 - 3 of 3 Answers

cocomany

  • Mar 14th, 2006
 

Compiler throws Error message
Try it.

  Was this answer useful?  Yes

Sreerenj

  • Mar 27th, 2006
 

If the project is compiled using /main switch with the compiler then the project compiles successfully.

For example:
class A
{
   public static void Main(string[] args)
   {
      Console.WriteLine("Main in class A");
    }
}

class B
{
   public static void Main(string[] args)
   {
      Console.WriteLine("Main in class B");
   }
}

Now compile with the /main switch with the C# compiler like
csc MultipleMain.cs /main:A

This will compile without error and while executing it will show Main in class A

Attempting to compile an application consisting of multiple classes with defined Main methods and not specifying the /main switch will result in a compiler error.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions