Visual Studio says "Method must have a return type"

user3477229 picture user3477229 · Mar 30, 2014 · Viewed 54.6k times · Source

It says

"Method must have a return type"

whenever I try to debug it.

I don't know how to fix this class

This is a player class for a c# coded 2d Game

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);
    }
}

Answer

FabianCook picture FabianCook · Mar 30, 2014

Your class is player but the constructor is Player, because they are different it is expecting Player to be a method rather than a constructor

Change the class name to Player and you will be good