【发布时间】:2019-01-02 20:17:37
【问题描述】:
我是编码初学者,英语不是我的母语。
请看一下这段代码和我的 cmets 好吗?
由于篇幅原因,我在课堂上省略了代码Player。
我想知道我要写什么而不是Alex.damage = int.Parse(Console.ReadLine());
namespace ConsoleApp5
{
class Player
{
private int _health = 100;
public int health
{
get
{
return _health;
}
}
public void damage (int _dmg)
{
_health -= _dmg;
}
}
}
class Programm
{
static void Main(string[] args)
{
Player Alex = new Player();
Console.WriteLine("Wie viel Damage soll ausgeteilt werden?"); // "How much
//damage should be done"
Alex.damage = int.Parse(Console.ReadLine()); // there is the error
//"'damage' is a methodgroup, therfore an assigment is not possible"
Console.WriteLine(Alex.health);
Console.ReadKey();
}
}
【问题讨论】:
-
欢迎来到 SO。请添加
Player类的代码。 -
好吧,我猜应该是
Alex.damage(int.Parse(Console.ReadLine()));和函数内部damage你会降低玩家的生命值 -
感谢 Fabjan,它成功了。太明显了^^
标签: c# methods properties readline