Re: Newbie - delete item from collection
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <F1158417DEA87742B373CDEDE85B05C802A484DB90@NYSRVNTSMAIL03.group1.local> |
One thing to try is to work from the end of the collection. When you delete items from some structures, the indexes above the deleted item are reduced to keep it from having gaps. So:
for (int idx = _someList.Count - 1; idx >= 0; idx--)
{
if (_someList[idx].ErrorCode > 90)
_someList.RemoveAt(idx);
}
--Jekke
-----Original Message-----
From: Discussion of advanced .NET topics. [mailto:[email protected]] On Behalf Of Lars Zeb
Sent: Monday, November 17, 2008 3:27 PM
To: [email protected]
Subject: [ADVANCED-DOTNET] Newbie - delete item from collection
I have defined a and populated a generic list with 3rd party software.
After it is created, I need to remove all items with an errorcode
value > 90.
Is this supposed to work?
for (int idx = 0; idx < _someList.Count; idx++)
{
if (_someList[idx].ErrorCode > 90)
_someList.RemoveAt(idx);
}
After I "removed" items with ErrorCode> 90, the list still contained some items with ErrorCodes over 90.
Or should I create a new list and add items to it from the old list with ErrorCodes <=90?
Thanks, Lars
===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives
This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Subject to applicable law, Group One Trading, LP may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free.
===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives