Cannot assign "money" because it is a "method group"

I am making a project for a class and I need to call a function Money

from my class Player

. However, I do not know how to change Money

to something else that is not Method Group

. I don't know much programming, so my range of solutions is pretty small. Also, the teacher said that I cannot make any changes to the class Main

, only to the class Player


Here's the code for the class Main


 p1.Money += 400;


And here's the Money function from my Player class:

public int Money ()
        return money;



source to share

2 answers


- method. You can't set it - it returns something ( int

) (or nothing, if void


You need to change it to a property that can also be set:

public int Money {get; set;}

or, in more detail:

private int _money;
public int Money { get { return _money; } set {_money = value;} }




It should be

money += 400;


or change the method to a property,

public int Money {get;set;}


Depending on where you are trying to increment (in a class or in a class that uses the Money property (field)



All Articles