Yes we can have different classes having main functions. Both class can have their own main functions. The program decides at compile time which main should be executed. So actually there is only one main function.
for example we have two classes class1 and class2 in a program. Now how the compiler will decide which main should be executed at runtime?
using System;
class Class1
{
public static void Main()
{
Console.WriteLine("Class 1");
}
}
class Class2
{
public static void Main()
{
Console.WriteLine("Class 1");
}
}
at compile time we are specifying that Class1 is containing our Main function and that will be execute at runtime.
csc filename.cs/main:Class1
No comments:
Post a Comment