Visual Studio说“方法必须具有返回类型". [英] Visual Studio says "Method must have a return type"
本文介绍了Visual Studio说“方法必须具有返回类型".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说
方法必须具有返回类型"
"Method must have a return type"
每当我尝试调试它时.
我不知道该如何解决此类问题
I don't know how to fix this class
这是C#编码2d游戏的玩家类
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);
}
}
推荐答案
您的类为player
,但构造函数为Player
,因为它们不同,因此它期望Player
是方法而不是构造函数
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
将班级名称更改为Player
,您会很好
Change the class name to Player
and you will be good
这篇关于Visual Studio说“方法必须具有返回类型".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文