不可调用成员“TalesOfMyroth()”不能像方法一样使用

Kai*_*des 1 c#

namespace Tales_Of_Myroth
{
    public class TalesOfMyroth
    {
        static void Main(string[] args)
        {
            TalesOfMyroth();  //here is my error
        }

        private Jogador _jogador;

        public TalesOfMyroth()
        {
            _jogador = new Jogador();

            _jogador.VidaAtual = 50;
            _jogador.VidaMaxima = 50;
            _jogador.Ouro = 0;

            Console.WriteLine("Vida: " + _jogador.VidaAtual);

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我本来想为我刚刚开始的大学制作一个简单的文字游戏......有人可以帮助我吗?(代码中的某些内容是用葡萄牙语编写的)

Mar*_*ark 5

TalesOfMyroth 是一个Class名字。所以你应该将它用作一个类。

static void Main(string[] args)
    {
        TalesOfMyroth Tales = new TalesOfMyroth();
    }
Run Code Online (Sandbox Code Playgroud)

如果您将程序的Main class和分开,这也很好。Class所以你会有 2 个 cs 文件。1 是给你的Main Class,另一个是给你的TalesOfMyroth class。然后将这两个文件放在同一个namespace.

如果您只想调用 a function,那么您应该添加void到您的, 中function,并使用与您的名称不同的名称class name

namespace Tales_Of_Myroth
{
    public class TalesOfMyroth
    {
        static void Main(string[] args)
        {
            Tales();
        }

        static private Jogador _jogador;

        public static void Tales()
        {
            _jogador = new Jogador();

            _jogador.VidaAtual = 50;
            _jogador.VidaMaxima = 50;
            _jogador.Ouro = 0;

            Console.WriteLine("Vida: " + _jogador.VidaAtual);

        }
    }
}
Run Code Online (Sandbox Code Playgroud)