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

  • Home
  • SEARCH
  • 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 6580833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:04:35+00:00 2026-05-25T16:04:35+00:00

Is there a better way to remove multiple items from a hash table based

  • 0

Is there a better way to remove multiple items from a hash table based on a condition, other than saving the keys first in a list and then iterating through that and removing each item one by one? the Generic list provides a “RemoveAll” method to which I can pass an anonymous function, but it seems there isn’t an equivalent approach for HashTable. note: I am using .NET framework 2.0

  • 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-25T16:04:36+00:00Added an answer on May 25, 2026 at 4:04 pm

    This really depends on your application. If your application is multi-threaded and pre .NET 4.0, it’s usually better to use a ReaderWriterLock/ReaderWriterLockSlim and get a reader lock, build a list of the keys you want to remove, then upgrade to a write lock, and perform a loop on the list to remove the keys. This way, while you are iterating over the Hashtable for keys to remove, other readers can access it without being locked out.

    Now if you can get to .NET 4.0, The ConcurrentDictionary is brilliant and has much less contention! If you stay in .NET 2.0, I’d recommend Dictionary even though it’s not part of your question per se.

    UPDATE If your application is not multi-threaded, no need to lock, but you still need to build the list of keys, because calling Remove() while iterating invalidates the enumerator. So basically, you’re doing it correctly given your comment to the question.

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

Sidebar

Related Questions

Is there better way to delete a parameter from a query string in a
Is there a better way to flash a window in Java than this: public
Is there a better way to forcefully disconnect all users from an Oracle 10g
Is there a better way to debug JavaScript than MS Script Editor? I am
Is there a better way than simply trying to open the file? int exists(const
Is there a better way to negate a boolean in Java than a simple
Is there a better way to watch for new entries in a table besides
Is there a better way of binding a list of base class to a
Is there a better way to do this? -(NSDate *)getMidnightTommorow { NSCalendarDate *now =
Is there a better way to do the following: $array = array('test1', 'test2', 'test3',

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.