Munesh  Sharma
Can i have more than Main() function in c#. Give the explanation
By Munesh Sharma in .NET on Mar 15 2011
  • Utsavi Bhatt
    May, 2018 16

    It is possible to have multiple Main() methods in C# program. But, you have to explicitly identify which Main method is the entry point at the run-time.

    • 0
  • sarika jain
    Mar, 2011 16

    Yes,We can have more than one Main function in C# program.............

    Just take an Example

    using System;
    class A
    {
    public static void Main()
    {
          Console.WriteLine("Class A");
    }
    }
    class B
    {
    public static void Main()
    {
          Console.WriteLine("Class B");
    }
    }
    class C
    {
    public static void Main()
    {
          Console.WriteLine("Class C");
    }
    }

    save this as file.cs.
    and in the cmd run this file
    as 
    command:--
    csc file.cs /main:classname 
    className is the name of the class which you want to compile now...


    I hope you get ur answer .if you are not satisfied rep soon..............and post your comments.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS