Question

I have a sample c# console project in which I have 2 program files:

  1. Program.cs
  2. Program02.cs

In Program.cs I have the usual main method that is the entry point of the project:

public static void main(string[] args)
{
    Console.WriteLine("hello world from Program.cs");
}

But I would like to make the execution of the program from the Program02.cs file so I added in the file the method.

public static void main(string[] args)
{
    Console.WriteLine("hello world from Program02.cs");
}

Clearly it doesn’t work, the entry point/execution of the project starts at Program.cs, how can I switch the main execution method to the Program02.cs file?

enter image description here enter image description here

enter image description here enter image description here

Was it helpful?

Solution

Right-click on the project in Solution Explorer, and locate:

  1. Common Properties
  2. General
  3. Application
  4. Startup Object and set it to the preferred class that contains your Main() method

!!! You declared your Main() method like this: main(), which is not correct. It must be Main(). C# is a case-sensitive language.

Check this: enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top