CSharp - What is the output: multiple Main() methods

Question

What is the output from the following code

Can we have multiple Main() methods in our program, like in the following?

using System;

namespace MultipleMainTest
{
    class Program1
    {
        static void Main(string[] args)
        {
            Console.WriteLine("I am inside Program1.Main(string[] args) now");

           Console.ReadKey();
        }
    }
    class Program2
    {
        static void Main()
        {
            Console.WriteLine("I am inside Program2.Main() now");
            Console.ReadKey();
        }
    }
}


Click to view the answer

Compile time error

Note

To avoid this error, set the entry point from your project properties in visual studio.

Related Quiz