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 7956867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:07:19+00:00 2026-06-04T04:07:19+00:00

I am currently working on a project where I have to manage large sets

  • 0

I am currently working on a project where I have to manage large sets of unique elements. Each element has ~20 Properties, and every element has a public property DateTime.

The property DateTime is not unique, so I cannot use a generic dictionary to store my data.

Currently I put those elements into an ObservableCollection, but the perfomance of removing elements from the collection is incredibly slow, I end up waiting ~20 seconds to remove ~7000 elements from a collection of ~25.000 elements.

(The search operation seems to be quite efficient, it takes only ~30 ms to find 80 randomly selected elements from an unsorted collection of 300.000 elements).

Each element implements the GetHashCode() method by simply returning the DateTime.GetHashCode().

I thought that using a HashSet rather than an ObservableCollection would increase my performance quite a bit, but it doesn’t seem to have an effect at all…

And using a generic dictionary is even worse…

Isn’t the HashSet more powerful than an ObservableCollection if the elements have “good” hash functions (there are very few elements that have the same hash code)??

  • 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-06-04T04:07:21+00:00Added an answer on June 4, 2026 at 4:07 am

    You have to override the Equals method of your objects.

    Because the HashSet uses an internal IEqualityComparer instance that usually first checks for (null) and then compares a “non-null” item with another item by using the overridden Equals method:

    class MyObject
    {
        public Guid Id { get; set; }
    
        public override bool Equals(object other)
        {
            if (other is MyObject)
            {
                // use the 'Id' property as identifier
    
                MyObject myObj = (MyObject)obj;
                return myObj.Id == this.Id;
            }
    
            // is not a 'MyObject' based object
            return base.Equals(other);
        }
    }
    

    You can also use strings or any other kind of objects that are comparable with your objects.

    EDIT:

    So you can use the HashSet instead of OberservableCollection. The last collection type is normally slower because on each collection change (add, remove, clear, insert, etc.) the PropertyChanged and the CollectionChanged events are fired.

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

Sidebar

Related Questions

I'm currently working on a fairly large project that has been migrated from Ant
Im currently working on a grizzly, spring and jersey project and i have encountered:
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
Hi Currently i am working on a rails project . where i have to
I have been working on keeping things object oriented for my project. Currently, I'm
I am currently working on a project where we have a couple very control
I am currently working on a project which has Employee, Manager entities. At the
I am currently working on a large project for a client, and to help
My team and me are currently working on quite a large project. We are
I'm working on a large, complex ASP.NET project. I have a dynamically loaded web

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.