c# enables us to define more than one class with the method. Main method is the entry point for program execution. So why do we want to have more than one place for program execution. What is the advantage of multiple main methods over single main method.
Edit:
Example.cs
Class Example_1
{
public static void Main()
{
System.Console.WriteLine("Example 1")
}
public void test()
{
System.Console.WriteLine("Test method")
}
}
Class Example_2
{
public static void Main()
{
System.Console.WriteLine("Example 2")
}
}
If I type “csc Example.cs” then what would happen ?
What to do if I want to inherit test method of Class Example_1 in Class Example_2. Will this code work.
Example_1 abc = new Example_1();
abc.test();
You could use it so that different build configurations built the same executable but with different entry points – for example a console entry point vs a WinForms entry point.
Personally I use it when giving talks and in the sample code for C# in Depth. Each file is a self-contained example, but it’s simpler to just have one entry point – so that entry point uses a utility class to prompt the user for which example they want to run.