Visual Studio说"方法必须有一个返回类型"

use*_*229 8 c# methods spritebatch

它说

"方法必须具有返回类型"

每当我尝试调试它.

我不知道怎么修这门课

这是ac#编码的2d游戏的玩家类

public class player
{
    public float moveSpeed;
    public Vector2 position;
    public Texture2D texture;

    //default constructer
    public Player(Texture2D tex, Vector2 startPos)
    {
        position  = startPos;
        texture   = tex;
        moveSpeed = 5.0f;
    }
    public void Update(GameTime gameTime)
    {
        //------------------------------------------
        //check for keyboard input(keyboard IF statements)

    }
    public void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.Draw(texture, position, Color.White);
    }
}
Run Code Online (Sandbox Code Playgroud)

Fab*_*ook 17

你的类是player构造函数Player,因为它们是不同的,它期望Player是一个方法而不是构造函数

将班级名称改为Player,你会很好


Jul*_*ano 9

您的班级名称是player小写的.当编译器找到类Player(大写)的构造函数时,它认为它是一个Player没有指定返回类型的方法.

所以只需将您的类重命名为大写Player.C#是区分大小写的,所以playerPlayer是两个不同的东西.


Dyl*_*eus 6

你的类是小写的玩家,你的构造函数是大写的。类名和构造函数应该始终相同并且区分大小写:)