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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:32:19+00:00 2026-06-13T01:32:19+00:00

I found an implementation of GetHashCode() that looks like this Guid _hashCode = Guid.NewGuid();

  • 0

I found an implementation of GetHashCode() that looks like this

    Guid _hashCode = Guid.NewGuid();
    public override int GetHashCode()
    {
        return _hashCode.GetHashCode();
    }

Even thought the Equals looks correct, is it correct to say this implementation will cause many assumptions about .NET to break?

       public override bool Equals(object obj)
    {
        if (obj.GetType() != trustedEntity.GetType())
            return false;

        TrustedEntity typedObj = (TrustedEntity)obj;

        if (trustedEntity.BackTrustLink != typedObj.BackTrustLink)
            return false;
        if (trustedEntity.ForwardTrustLink != typedObj.ForwardTrustLink)
            return false;
        if (trustedEntity.EntryName != typedObj.EntryName)
            return false;

        return true;
    }

The counter argument I’m hearing is that GetHashCode needs to never change once the object is created. This is because this object is stored in a dictionary.

Can someone clear this up for me and explain what needs to happen to GetHashCode if the object changes, that ultimately changes the Equals method?

  • 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-13T01:32:20+00:00Added an answer on June 13, 2026 at 1:32 am

    From MSDN (Notes to Implementers section):

    A hash function must have the following properties:

    1. If two objects compare as equal, the GetHashCode method for each
      object must return the same value. However, if two objects do not
      compare as equal, the GetHashCode methods for the two object do not
      have to return different values.

    2. The GetHashCode method for an object must consistently return the
      same hash code as long as there is no modification to the object state
      that determines the return value of the object’s Equals method. Note
      that this is true only for the current execution of an application,
      and that a different hash code can be returned if the application is
      run again.

    3. For the best performance, a hash function must generate a random
      distribution for all input.

    Depending on the Equals method for this object, you may be violating the first point from the documentation as well.

    More excellent reading

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

Sidebar

Related Questions

It looks easy, but I found the implementation tricky. I need that for a
I found a goodlooking example about implementation enums in a different way. That is
In Matters Computational I found this interesting linear search implementation (it's actually my Java
I searched for an implementation of std::map runtime ordering and have found this solution:
When I looked into the implementation of java.util.UUID.fromString , I found that it doesn't
cipher = Cipher.getInstance(Blowfish); This throws an exception java.security.NoSuchAlgorithmException: Cipher Blowfish implementation not found. I
I found an implementation of a priority queue that primarily uses CFBinaryHeap to work.
I found an implementation of the associative array here and would like to understand
i'm using this example implementation found at http://tangentsoft.net/wskfaq/examples/basics/select-server.html This is doing most of what
Trying to get my mind around google protobuf. I found some implementation of protobuf

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.