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

The Archive Base Latest Questions

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

It always seems to just work without ever having to do anything. The only

  • 0

It always seems to just “work” without ever having to do anything.

The only thing I can think of is that each class has a hidden sort of static identifier that Object.GetHashCode uses. (also, does anyone know how Object.GetHashCode is implemented? I couldn’t find it in the .NET Reflector)

I have never overridden GetHashCode but I was reading around and people say you only need to when overriding Equals and providing custom equality checking to your application so I guess I’m fine?

I’d still like to know how the magic works, though =P

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

    It always seems to just “work” without ever having to do anything.

    You didn’t tell us if you’re using value types or reference types for your keys.

    If you’re using value types, the default implementation of Equals and GetHashCode are okay (Equals checks if the fields are equals, and GetHashCode is based on the fields (not necessarily all of them!)). If you’re using reference types, the default implementation of Equals and GetHashCode use reference equality, which may or may not be okay; it depends on what you’re doing.

    The only thing I can think of is that each class has a hidden sort of static identifier that Object.GetHashCode uses.

    No. The default is a hash code based on the fields for a value type, and the reference for a reference type.

    (also, does anyone know how Object.GetHashCode is implemented? I couldn’t find it in the .NET Reflector)

    It’s an implementation detail that you should never ever need to know, and never ever rely on it. It could change on you at any moment.

    I have never overridden GetHashCode but I was reading around and people say you only need to when overriding Equals and providing custom equality checking to your application so I guess I’m fine?

    Well, is default equality okay for you? If not, override Equals and GetHashCode or implmenet IEqualityComparer<T> for your T.

    I’d still like to know how the magic works, though =P

    Every object has Equals and GetHashCode. The default implementations are as follows:

    1. For value types, Equals is value equality.
    2. For reference types, Equals is reference equality.
    3. For value types, GetHashCode is based on the fields (again, not necessarily all of them!).
    4. For reference types, GetHashCode is based on the reference.

    If you use a overload of Dictionary constructor that doesn’t take a IEqualityComparer<T> for your T, it will use EqualityComparer<T>.Default. This IEqualityComparer<T> just uses Equals and GetHashCode. So, if you haven’t overridden them, you get the implementations as defined above. If you override Equals and GetHashCode then this is what EqualityComparer<T>.Default will use.

    Otherwise, pass a custom implementation of IEqualityComparer<T> to the constructor for Dictionary.

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

Sidebar

Related Questions

I have a winforms datagridview that seems to always have at least one row
It seems to me that one should always properly dispose resources when calling Directory
It seems that my Sql Server Full text catalog is not always up to
From a couple of preliminary tests it seems that EnumWindows always returns windows in
I have 2 questions on this My code always seems to hit a 401
I have tried this a few different ways and it always seems to fail.
UITableViewController seems to always hijack the View link in IB. So, if I put
With regards to making a game server, it seems Erlang always comes up as
It seems like management always is saying how the project is late, then we
This seems like a pretty softball question, but I always have a hard time

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.