I'm working on an application that uses a list to handle previous guesses from the user. Below is the (private) list and the property for accessing the list.
To prevent privacy leak i'm using a ReadOnlyCollection, which is also the reason for me only having a getter in the property (elements are added inside the class directly to the list, not through the property).
Now to the problem. The code below generates to error message:
How can this be solved? Thanks in advance!
private List<int> _previousGuesses;
public ReadOnlyCollection<int> PreviousGuesses {
get {
return _previousGuesses;
}
}
EDIT: Ok, so problem nr 2 is solved (thanks Zortkun!). What about the first problem, that I can't use only a getter, any ideas?
I guess the favor is not to post the first thing that pops up on google but how about this?
return _previousGuesses.AsReadOnly();
From here