-6

why i can't run my program it's says CS5001: exe does not contain a static 'Main' method suitable for an entry point

This is my Code in C#:

using System;

class Human { private int _distance = 0; private int _wordsSpoken = 0;

public void Walk()
{
    Console.WriteLine("Walking");
    _distance++;
}

public void Speak()
{
    string[] phrases = {
        "How are you?",
        "It is a lovely day. Isn't it?",
        "It's a pleasure to meet you.",
        "Hello.",
        "A pleasant morning to you."
    };

    Random rand = new Random();
    int index = rand.Next(phrases.Length);
    Console.WriteLine(phrases[index]);
    _wordsSpoken++;
}

public void Hop()
{
    Console.WriteLine("Hop");
    _distance += 2;
}

public int Distance
{
    get { return _distance; }
}

public int WordsSpoken
{
    get { return _wordsSpoken; }
}

}

  • 1
    `static void Main() {...}` in the *entry point* - this method will be call to run your program https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/main-command-line – Dmitry Bychenko Feb 11 '23 at 19:30

1 Answers1

-1

You need to include this in your code:

static void Main(string[] args)
{
    // call your first method or whatever you need
}

This method is the starting point for your program and it is required. You would usually put this at the top of your code.

Pete
  • 106
  • 7
  • This question is a duplicate of at least a dozen others, and should be flagged as a duplicate instead of being answered yet again. – Ken White Feb 11 '23 at 19:37
  • By "flag as a duplicate" Ken White meant Flag > Needs Improvement > Duplicate > then select an existing Q&A that addresses this issue. – Henry Ecker Feb 11 '23 at 19:59