Interviews2 answers
Can i have more than Main() function in c#. Give the explanation
2 Answers
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.
Utsavi BhattPosted May 16, 2018, 7:07 AM EDT
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.
sarika jainPosted Mar 16, 2011, 7:59 PM EDT