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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:12:16+00:00 2026-06-12T08:12:16+00:00

I am stumped by a seemingly simple problem. I have two objects that I

  • 0

I am stumped by a seemingly simple problem. I have two objects that I am comparing with a !=.

When I run the application, a != b is true.
When I put a breakpoint and do a Watch, a.GetHashCode() == b.GetHashCode() is true.

These two (reference type) objects are defined in a different assembly, but I cannot find an override to the != method (although GetHashCode is overridden). Is there another explanation for this? Could it be possible that a GetHashCode for two objects could be the same, but a not-overriden != would return true?

Thanks.

  • 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-12T08:12:18+00:00Added an answer on June 12, 2026 at 8:12 am

    When two objects that are different return the same code it is called a “collision”. With only ~4 billion possible integer values, and more than 4 billion possible values of [your class name here] some collisions are inevitable. This is why a hash based structure (i.e. Dictionary) can’t rely entirely on GetHashCode, it also needs a sensible Equals implementation to be effective. The Equals method is what is used to resolve these collisions.

    Of course it’s also possible that the creator of the class overwrite either GetHashCode or Equals and in some way made a mistake that in some way violated the “contract” for generating hash codes. Here is one list of guidelines to keep in mind when creating your GetHashCode methods. Remember that there is a fairly small set of things that you have to do, and another set of things that can be done to make it work efficiently.

    return 0; is actually a perfectly acceptable GetHashCode implementation. It conforms with all of the rules, it just has a 100% chance of causing collisions, so it will be extraordinarily inefficient and you shouldn’t ever actually do that.

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

Sidebar

Related Questions

I'm stumped by a seemingly simple problem. In my ASP.NET page, I have a
Stumped with what looks like simple problem. I have var SummaryCollection = (from n
I'm stumped by this seemingly trivial problem... I would like to use python to
I have been stumped all day on this problem. Basically I want to check
This one's stumped me. So I have the following sample app that is supposed
Well I am stumped. I have a access DB that I need to convert
Im stumped by this simple query because its one I have not tried before.
I am completely stumped. I have a program that pulls information stored in a
I'm completely stumped on this one. I have three different lists that need to
I am stumped with this problem. ActiveSupport::JSON defines to_json on various core objects 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.