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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:16:32+00:00 2026-06-05T04:16:32+00:00

I have a CustomObject object which overrides GetHashCode(). I have a HashSet, and I

  • 0

I have a CustomObject object which overrides GetHashCode().
I have a HashSet, and I am able to call add with two distinct object having the same hash code.
Both get added and later on I end up with some database insertion troubles (primary key duplicates)… The purpose of using a hashSet was connected to these database insertions (avoiding key collisions).

Am I possibly missing out on some properties of HashSet ? Even when I try checking (.Contains) before adding (.Add), I end up adding hashCode duplicates…

  • 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-05T04:16:34+00:00Added an answer on June 5, 2026 at 4:16 am

    Because HashSet<T> membership is based on object equality, not hash code equality. It’s perfectly legal for every member of a HashSet<T> to have the same hash code as long as the members are different according to Equals. The role that hash codes play in HashSet<T> is for rapid testing of membership. If you have an object and its hash code is not in the HashSet<T>, then you know that the object is not in the HashSet<T>. If you have an object and its hash code is in the HashSet<T>, then you have to walk the chain of objects with that same hash code testing for equality using Equals to see if the object is actually in the HashSet<T> or not. That’s why a balanced hash code distribution is important. But it is not the case that unique hash codes are necessary.

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

Sidebar

Related Questions

What I want to have is a custom object which provides some events. For
I have a class CustomCollection : IList which maintains a list of CustomObject Types.
I have a custom object called Technology__c and join object called AccountTechnologies which is
(sorry about the long title) I have a custom object Person, which in turn
I have couple of objects(1 custom object called appointment and event object) which i
I have one costum object which has a reference to another custom object. How
I have an NSTableView which displays some information representing a custom object of mine.
I have a custom object of School, which is part of a family of
At the moment I have an object of type A which is being viewed
We have a custom object in Salesforce called domain which reflects each website we

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.