How do I create multiple entry points and specify which one to use?
To create multiple entry points you simply add multiple classes, each
with a static Main function:
using System; namespace MultipleEntryPoints { class Class1 { class Point1 { [STAThread] static void Main(string[] args) { Console.WriteLine(“This is point 1”); } } class Point2 { [STAThread] static void Main(string[] args) { Console.WriteLine(“This is point 2”); } } class Point3 { [STAThread] static void Main(string[] args) { Console.WriteLine(“This is point 3”); } } } } |
In Visual C# .NET, to configure which entry point you want to be the startup entry point you click on Properties in the menu that appears when you right click the project in the Solution Explorer window. On the left pane go to Common Properties -> General. Now you can change the Startup object field:
If you are compiling from the command prompt and you want let’s say… to select as a startup object the Point2 class you would use the following:
csc.exe Class1.cs /main:MultipleEntryPoints.Class1.Point2 |
If you don’t specify a startup object and you have multiple entry points you’ll get an error for each entry point:
…has more than one entry point defined…