-5

I couldn't find solution in the former questions. Please help. I want to do more excercises and run them differently. Like now run the Excercise1() and I can just run it differently. I should need a fuction, which calls the excercises. I couldn't do that, but if I have 1 Excercise, it also doesn't work, because of "CS5001 C# Program does not contain a static 'Main' method suitable for an entry point". Sorry if my question is trivial, for me not. Can you help me to fix it this main method?

  using System;
  namespace normal
  {
    public class Program
    {
      public static void Excercise1()
         {}
//I want something like this more: 
      public static void Excercise2()
      { }
    }
  }
foreigner
  • 1
  • 1
  • 2
  • The first thing you should start to do with a problem you cant resolve is to google the error message. There are millions of answers ready and waiting for you on this site alone. – Ňɏssa Pøngjǣrdenlarp Dec 24 '19 at 14:30

3 Answers3

0

As the error states, you need a static Main method. This will be called when you execute the program. It is the entry point of it.

Just add:

public static void Main(){
    // Here you want to call your exercise functions
}
Alvin Sartor
  • 2,249
  • 4
  • 20
  • 36
0

Provide a static method named Main or don't compile it as an exe.

public static void Main()
{
}
Tanveer Badar
  • 5,438
  • 2
  • 27
  • 32
0

A C# program must have a static method called Main in order to be valid. It has the following signature:

private static void Main(string[] args)
{
  ...
}

Your program should therefore look like this:

using System;

namespace Normal
{
  public class Program
  {
    private static void Main(string[] args)
    {
      Exercise1();
      Exercise2();
    }
    public static void Excercise1()
    {
    }
    public static void Excercise2()
    {
    }
  }
}

Without the Main static method, the C# compiler wouldn't know where your program's start point is.

There are, of course, cases where you don't need an entry point to your program. When you're developing a library (a DLL), it's not meant to run by itself, but other code is going to call its methods. In this case, though, I think you're aiming for a program with an actual entry point.

Alexander van Oostenrijk
  • 4,644
  • 3
  • 23
  • 37
  • Thank you so much! And how can I do to run the Excercise2() and not the Excercise1(), how can I jump there? – foreigner Dec 24 '19 at 15:28