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:
- TheNameOfTheClass.PreviousGuesses.get must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.
- Cannot implicity convert type 'System.Collections.Generic.List' to 'System.Collections.ObjectModel.ReadOnlyCollection.
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?