By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

Read-only collection...

P: n/a
Maybe a dumb question (if those exist), but how do you...

Private m_Stuff As New System.Collections.ArrayList

Public ReadOnly Property Stuff() As System.Collections.ArrayList
Get
Return m_Stuff
End Get
End Property

disable the Add and AddRange methods (or something similar), so the
property becomes a read-only array/list in addition to being one that can't
be replaced?

Implement enumeration yourself, or is there an easier method?
Apr 5 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

Lucvdv wrote:
Maybe a dumb question (if those exist), but how do you...

Private m_Stuff As New System.Collections.ArrayList

Public ReadOnly Property Stuff() As System.Collections.ArrayList
Get
Return m_Stuff
End Get
End Property

disable the Add and AddRange methods (or something similar), so the
property becomes a read-only array/list in addition to being one that can't
be replaced?

Implement enumeration yourself, or is there an easier method?


The Framework authors have done this for you. ArrayList (in common with
many other collections, I think) has a Shared method called ReadOnly
which:

Returns a list wrapper that is read-only.

Overload List

Returns a read-only ArrayList wrapper.

[Visual Basic] Overloads Public Shared Function ReadOnly(ArrayList) As
ArrayList

Returns a read-only IList wrapper.

[Visual Basic] Overloads Public Shared Function ReadOnly(IList) As
IList

--
Larry Lard
Replies to group please

Apr 5 '06 #2

P: n/a
In 2005 use the generic ReadOnlyCollection(Of T) class
In 2003 make your own by inheriting ReadOnlyCollectionBase

/claes

"Lucvdv" <re**********@null.net> wrote in message
news:l0********************************@4ax.com...
Maybe a dumb question (if those exist), but how do you...

Private m_Stuff As New System.Collections.ArrayList

Public ReadOnly Property Stuff() As System.Collections.ArrayList
Get
Return m_Stuff
End Get
End Property

disable the Add and AddRange methods (or something similar), so the
property becomes a read-only array/list in addition to being one that
can't
be replaced?

Implement enumeration yourself, or is there an easier method?

Apr 5 '06 #3

P: n/a
On 5 Apr 2006 06:54:04 -0700, "Larry Lard" <la*******@hotmail.com> wrote:
The Framework authors have done this for you. ArrayList (in common with
many other collections, I think) has a Shared method called ReadOnly
which:


Thanks.

I expected something like that, but didn't dig deep enough. I went looking
for a 'readonly' or similar method/property in intellisense, and didn't see
it because it doesn't show up unless you select the "all" tab in 2005 or go
looking for it via the type itself instead of through an instance.
Apr 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.