473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Read-only collection...

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
3 1995

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Steve | last post by:
Hi, I'm trying to convert a file reading loop into one using streams. The BSD OS read API returns the number of bytes read, but istream::read returns itself. How can I find out the number of...
12
by: Steven T. Hatton | last post by:
I know of a least one person who believes std::ifstream::read() and std::ofstream::write() are "mistakes". They seem to do the job I want done. What's wrong with them. This is the code I...
2
by: Sandman | last post by:
Just looking for suggestion on how to do this in my Web application. The goal is to keep track of what a user has and hasn't read and present him or her with new material I am currently doing...
2
by: Andrea Bauer | last post by:
Hallo, wie kann ich so eine Datei unter .Net schreiben C++ oder C#. Bitte mit Funktionsaufrufen. Vielen Dank. Grüße Andrea <Product> <ProgramNumber>2</ProgramNumber>
4
by: Ollie Cook | last post by:
Hi, I am having some difficulty with read(2) and interrupting signals. I expect I am misunderstanding how the two work together, so would appreciate some guidance. I am trying to 'time out' a...
1
by: Jose Reckoner | last post by:
I'm running python 2.3 on Windows XP. Anyone have a quick small script to convert .DT1 and .DEM data to ASCII or some other format? I don't need a viewer. Thanks!
0
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
4
by: zl2k | last post by:
hi, there I have a appendable binary file of complex data structure named data.bin created by myself. It is written in the following format: number of Data, Data array Suppose I have...
5
by: Thomas Christensen | last post by:
This issue has been raised a couple of times I am sure. But I have yet to find a satisfying answer. I am reading from a subprocess and this subprocess sometimes hang, in which case a call to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.