Home All Groups Group Topic Archive Search About

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

Author
15 Aug 2006 7:56 PM
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

Author
16 Aug 2006 2:25 AM
Emby
Would a collection suit your purpose? If so, have a look at this generic
collection class:
    System.Collections.ObjectModel.ReadOnlyCollection(Of T)

HTH ...

Show quote
"ThunderMusic" <NoSpAmdanlatathotmaildotcom@NoSpAm.com> wrote in message
news:e6GyETKwGHA.5056@TK2MSFTNGP06.phx.gbl...
> 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
>
Author
16 Aug 2006 2:24 PM
ThunderMusic
thanks a lot...  exactly what I needed...

Show quote
"Emby" <e***@blaisesoft-xxx.com> wrote in message
news:OkHZKtNwGHA.4756@TK2MSFTNGP02.phx.gbl...
> Would a collection suit your purpose? If so, have a look at this generic
> collection class:
>    System.Collections.ObjectModel.ReadOnlyCollection(Of T)
>
> HTH ...
>
> "ThunderMusic" <NoSpAmdanlatathotmaildotcom@NoSpAm.com> wrote in message
> news:e6GyETKwGHA.5056@TK2MSFTNGP06.phx.gbl...
>> 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
>>
>
>

AddThis Social Bookmark Button