Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 326117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:16:47+00:00 2026-05-12T09:16:47+00:00

I need to iterate through a LinkedList<T> (in .NET 2.0) and remove all the

  • 0

I need to iterate through a LinkedList<T> (in .NET 2.0) and remove all the items according to a given criteria.
It was easy way under Java, since I could do the following:

Iterator<E> i = list.iterator();
while (i.hasNext()) {
    E e = i.next();
    if (e == x) {
        // Found, so move it to the front,
        i.remove();
        list.addFirst(x);
        // Return it
        return x;
    }
}

Unfortunately, in the .NET behavior of IEnumerator<T> (the equivalent of Iterator<E>) there’s no remove method to remove the current element from the collection.
Also, in the LinkedList<T> there’s no way to access an element at a given index, to accomplish the task by iterating back from the last to the first.

Have you got any idea on how to do it? Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:16:47+00:00Added an answer on May 12, 2026 at 9:16 am

    This will remove all nodes that match a criteria, in one loop through the linked list.

    LinkedListNode<E> node = list.First;
    
    while (node != null)
    {
        var next = node.Next;
        if (node.Value == x) {
            list.Remove(e);
        }
        node = next;
    }
    

    I believe that’s what you’re attempting… You also added back in the node at the beginning of the list (so your java code didn’t remove all of the nodes, but rather moved the first matching to the beginning of the list). That would be easy to do with this approach, as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a large N, I need to iterate through all phi(k) such that 1
I need to iterate through the items (strings) in a CComboBox to check which
I have a property within a class, that I need to iterate through all
I need to create feature which will iterate through all subsites of site collection
I need to iterate through all words of english dictionary & filter certain based
In my script, I need to iterate through a range of dates given the
I need to iterate through all the keys in my NSUserDefaults and transfer them
I need to iterate through all of the collections in my MongoDB database and
I need to iterate through the fields on a table and do something if
Say I have components that I need to iterate through, for example From and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.