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

  • Home
  • SEARCH
  • 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 826937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:29:39+00:00 2026-05-15T03:29:39+00:00

Possible Duplicate: What is the best algorithm for an overridden System.Object.GetHashCode? What constitutes a

  • 0

Possible Duplicate:
What is the best algorithm for an overridden System.Object.GetHashCode?

What constitutes a good implementation of the GetHashCode method? I did some googling, and found some goodlines (MSDN) but it seems like the logic just manipulates two numbers stored as fields in the class. Is the actual logic this simple to implement this 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-05-15T03:29:40+00:00Added an answer on May 15, 2026 at 3:29 am

    The minimum requirement is that the hash code should be the same for any given value. So, this implementation works, but the distribution is horrible:

    public override int GetHashCode() {
      return 1;
    }
    

    To work best, the hash codes should consider all relevant data in the object and be as evenly distributed as possible within the integer range.

    An implementation that does consider all members, but doesn’t give very good distribution can be found in the System.Drawing.Point structure. It uses XOR to combine the bits in the members, which means that all points where X and Y are equal get the hash code zero:

    public override int GetHashCode() {
      return this.X ^ this.Y;
    }
    

    One way to get a better distribution is to multiply a member by a prime number and add the next member, repeating as needed:

    public override int GetHashCode() {
      return ((this.Value1 * 251) + this.Value2) * 251 + this.Value3;
    }
    

    The same method has been used in simple random generators, as it scatters the values pretty well.

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

Sidebar

Ask A Question

Stats

  • Questions 439k
  • Answers 439k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would create a MyWCFService class which would wrap all… May 15, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer You could be more specific: (\S*)\s(\S*)\s(\S*)\s(\S*)\s(\S*)\s(\S*)\s \S matches a non-space… May 15, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer There is no such thing as an "escape sequence" for… May 15, 2026 at 4:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.