2
Reply

Iterate LinkedLists without Enumerators?

Phil Ings

Phil Ings

Mar 30 2006 7:29 PM
2.7k
Hi, I'm really a complete beginner with C# though I'm familiar with other languages, so I'm probably gonna have some simple ( and possibly stupid ) questions. The programming language I'm coming from ( a proprietary one, not one many of you will be familiar with ) has inbuilt linked lists, which can hold object references, uses an EachIn Directive to iterate through them and generally gives a very good impression of being just like C#s linked lists, albeit that you can mix and match objects of different types. Anyway, I have my list of objects, which I iterate through, check the age of each and remove them from the list if they're over a certain age or meet certain criteria. This is, of course, no problem if you can change the structure of a list while iterating through it, but I've learned that you cannot do this in C#, and it will ( and has ) throw an exception if you try. So how am I supposed to iterate through the list without using an Enumerator? I've tried Intellisense on the list, but it doesn't give me many methods and none of them look promising. Beyond that a really good article on .Net 2.0's new LinkedLists based on Generics would be great, because neither of the two C# books I own cover LinkedLists at all, and only one even covers generics and collections. I've scoured the web but good articles on LinkedList seem to be few and far between. All the articles I have found cover adding, and removing all ( at once ) and pretty much nothing else. I've tried searching the articles on this site, of course, but it times out before it ever finds anything, so.. have to stick with google on that.

Answers (2)