Re: Newbie - delete item from collection
Ron Young <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <[email protected]> |
Are you using .NET 3.5 by chance? If so then Int[] x = someList.Where(item => item.ErrorCode <> 90); -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[email protected]] On Behalf Of Steve Johnson Sent: Monday, November 17, 2008 2:43 PM To: [email protected] Subject: Re: [ADVANCED-DOTNET] Newbie - delete item from collection On Mon, Nov 17, 2008 at 3:26 PM, Lars Zeb <[email protected]> wrote: > 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? > Yes, create a new list. As you enumerate the original list, store refs to items to be removed in the new list. Then enumerate the new list and remove each item from the original list. -- Steve Johnson =================================== View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives =================================== View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives