How do I create multiple entry points and specify which one to use?

How do I create multiple entry points and specify which one to use

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

Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to Geekpedia.com. With a passion for coding and a knack for simplifying complex tech concepts, Nathan has authored several popular tutorials on C# programming, ranging from basic operations to advanced coding techniques. His articles, often characterized by clarity and precision, serve as invaluable resources for both novice and experienced programmers. Beyond his technical expertise, Nathan is an advocate for continuous learning and enjoys exploring emerging technologies in AI and software development. When he’s not coding or writing, Nathan engages in mentoring upcoming developers, emphasizing the importance of both technical skills and creative problem-solving in the ever-evolving world of technology. Specialties: C# Programming, Technical Writing, Software Development, AI Technologies, Educational Outreach

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top