无法分配给“金钱",因为它是“方法组" [英] Cannot Assign to 'Money' Because It Is a 'Method Group'
问题描述
我正在为一个类做一个项目,我必须从我的Player
类中调用Money
函数.但是,我不知道如何将Money
更改为不是Method Group
的其他内容.我不太了解编程,所以我的解决方案范围很小.
另外,讲师说我不能对Main
类进行任何更改,只能对Player
类进行更改.
I'm doing a project for class, and I have to call the Money
function from my Player
class. However, I do not know how to change Money
into something else that is not a Method Group
. I don't know much programming, so my range of solutions is rather small.
Also, the instructor said I cannot make any changes to the Main
class, only to the Player
class.
这是Main
类的代码:
p1.Money += 400;
这是我的Player类中的钱"功能:
And here's the 'Money' function from my Player class:
public int Money ()
{
return money;
}
推荐答案
Money()
是一种方法.您无法设置它-它只会返回某内容(一个int
)(如果返回void
,则什么都不会返回).
Money()
is a method. You can't set it - it only returns something (an int
) (or nothing if void
).
您需要将其更改为也可以是属性设置:
You need to change it to a property that can also be set:
public int Money {get; set;}
或更详尽地说:
private int _money;
public int Money { get { return _money; } set {_money = value;} }
这篇关于无法分配给“金钱",因为它是“方法组"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!