473,385 Members | 1,445 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,385 software developers and data experts.

Collection readonly restriction review

I posted this a few posts ago and nobody responded, probably because nobody
gives a rat's ass. But i'd like to suggest that the readonly restriction
when iterating a collection be reviewed. I have no idea how this is
implemented internally but the implimentation is obviously distorting the
final code implementation and promoting bad software practices.

The issue is if you iterate a collection you aren't allowed to change the
collection during iteration. The only ways I've found so far is to

1. Use an isolator class written by Eric Gu for that explicit purpose which
sits between the collection and the iteration mechanism
2. Swallow the exception and brute force match on
3. Ignore it

I won't wast your time with why 2 and 3 are shameful and criminal. 1 is
tedious. But the catch is that iterating a collection and attempting to
change it is extremely common even for newbies attempt to get up to speed.
So can we have this addressed please or somebody yell at me for not seeing
an easier way?

--
Regards,
Alvin Bruney
Got DotNet? Get it here...
http://www.networkip.net/dotnet/tidbits/default.htm
Nov 15 '05 #1
1 1279
Alvin,

Use a for loop on the indexer method. Iterators are meant to be read-only (C
Sharp .NET Show). The reasoning is that iterators
are NOT thread safe and/or can be multiple refs to iterators for the same
collection.
"Alvin Bruney" <vapor at steaming post office> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
I posted this a few posts ago and nobody responded, probably because nobody gives a rat's ass. But i'd like to suggest that the readonly restriction
when iterating a collection be reviewed. I have no idea how this is
implemented internally but the implimentation is obviously distorting the
final code implementation and promoting bad software practices.

The issue is if you iterate a collection you aren't allowed to change the
collection during iteration. The only ways I've found so far is to

1. Use an isolator class written by Eric Gu for that explicit purpose which sits between the collection and the iteration mechanism
2. Swallow the exception and brute force match on
3. Ignore it

I won't wast your time with why 2 and 3 are shameful and criminal. 1 is
tedious. But the catch is that iterating a collection and attempting to
change it is extremely common even for newbies attempt to get up to speed.
So can we have this addressed please or somebody yell at me for not seeing
an easier way?

--
Regards,
Alvin Bruney
Got DotNet? Get it here...
http://www.networkip.net/dotnet/tidbits/default.htm

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kakaiya | last post by:
Error message: An unhandled exception of type 'System.InvalidCastException' occurred in test.dll Additional information: Specified cast is not valid. Public Class Form1 Inherits...
3
by: jamie_m_ | last post by:
I have a custom collection ... clFile that INHERITS from NameObjectCollectionBase the problem is, when I try to create an xmlserializer instance i get an error You must implement a default...
5
by: cody | last post by:
I know I can use ArrayList.ReadOnly() to create a readonly version of it, but how can I achive a similar thing with a generic collection of .NET 2.0?
6
by: rodchar | last post by:
hey all, Dim _oItems As Outlook.Items Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) _oItems = oInbox.Items I can iterate thru this with a...
10
by: Chet Cromer | last post by:
I am creating a set of base classes and sub classes to use throughout a program I'm developing. The base class represents a generic "lookup table" from my database that contains lists of things...
4
by: Michael | last post by:
Dear all .. If I want to use develop a user control and declare a public property which the type is System.Windows.Forms.GridTableStylesCollection For example : Public Class LookAndView...
14
by: Rich | last post by:
Yes, I need to store some values in an array type collection object that can hold 3 or more parameters per index. I have looked at the collection object, hashtable object and would prefer not to...
6
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
6
by: Erick | last post by:
I've created a class called Procs and a collection class called Processes which uses a hastable object to store the Procs. Now i want to enumerate with the "For each" to extract all the Procs in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.