Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Message "CS5001 Program does not contain a static 'Main' method suitable for an entry point", have multiple classes

So here's the deal, I have 2 classes at the moment (planning on adding multiple), and I get this error when i'm trying to call functions from both classes. Same namespace. I double-checked and look at my properties tab to see that it's set to compile.

using System;

namespace Game
{
public class SecondSet
{

    public void SituationSecondOne()
    {
        Console.WriteLine(" ");
        Console.WriteLine("Choices:");
        Console.WriteLine("1: First");
        Console.WriteLine("2: Second");
        Console.WriteLine(" ");

        int ChoiceOne = Convert.ToInt32(Console.ReadLine());

        switch (ChoiceOne)
        {
            case (1):
                Console.WriteLine("TEST2");
                break;
            case (2):
                Console.WriteLine("TEST2");
                break;
            case (1337):
                Console.WriteLine(" ");
                Console.WriteLine("Thank you for playing");
                Console.ReadLine();
                Environment.Exit(1);
                break;
            default:
                Console.WriteLine(" ");
                Console.WriteLine("Now, let's try that again ... (¬_¬)");
                SituationSecondOne();
                break;
        }
    }
 }
}

Now, when I call the function from the second to the first, I get no error. What type of Main() method do I need for this? (I also tried to add the original public void Main(string[] args), once added, I can no longer add public to the function I want to call to the first class)

NOTE: I added this to the first class

SecondSet s2 = new SecondSet();

And it works fine as the code is posted above, but I get the compile error mentioned. valve pls fix :/

like image 744
gauss Avatar asked Oct 26 '25 18:10

gauss


1 Answers

It's not clear what you mean.But I was looking at this issue as well, and in my case the solution was too easy. I added a new empty project to the solution. The newly added project is automatically set as a console application. But since the project added was a 'empty' project, no Program.cs existed in that new project. (As expected)

All I needed to do was change the output type of the project properties to Class library

Change the Output Type under the Project > Properties to that of a “Class Library”. By default, this setting may have been set to a “Console Application”.

   static void Main()
   {
   }
like image 166
Ali Tooshmalani Avatar answered Oct 29 '25 08:10

Ali Tooshmalani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!