readonly List as a property, how can I achieve this?

T

ThunderMusic

Hi,
I have the following :

private List<int> _myList = new List<int>();
public List<int> myList
{
get { return _myList; }
}

What I want is that the user cannot modify the content of the list, it can
only see what's in it. Is it something I can do or will I have to implement
my own collection class based on List<>?

thanks

ThunderMusic
 
E

Emby

Would a collection suit your purpose? If so, have a look at this generic
collection class:
System.Collections.ObjectModel.ReadOnlyCollection(Of T)

HTH ...
 
T

ThunderMusic

thanks a lot... exactly what I needed...

Emby said:
Would a collection suit your purpose? If so, have a look at this generic
collection class:
System.Collections.ObjectModel.ReadOnlyCollection(Of T)

HTH ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top