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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:54:01+00:00 2026-05-25T14:54:01+00:00

Short question: How do I get the object.GetHashCode() value for an object that has

  • 0

Short question: How do I get the object.GetHashCode() value for an object that has re-implemented GetHashCode()?

Long story:
So I have about a hundred thousand objects, each sharing many (non-compile time) common strings. Common as in if the value is equal, it is the same instance.

Knowing that, I figure I’d rather use a standard object comparison (ReferenceEquals) rather than a full string compare – particularly as these are looked up in dictionaries on a fairly regular basis.

So I declare a class ReferenceEqualityComparer : IEqualityComparer to use with a Dictionary<string, TValue>, figuring it’d be useful to have anyway, and go about trying to implement the two methods.

Equals is easy enough, use object.ReferenceEquals.

But how do I get the equivalent of object.GetHashCode() for the GetHashCode method?

ie how do I get some representation of an object’s instance?

I know there are other ways I can go about doing this – create an InternedString class which holds a reference to the string, but does not implement Equals or GetHashCode, or store indexes rather than strings with each object, but I’m now curious – is there actually a way to implement a generic ReferenceEqualityComparer?

  • 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-25T14:54:02+00:00Added an answer on May 25, 2026 at 2:54 pm

    Have a look at RuntimeHelpers.GetHashCode(object).

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

Sidebar

Related Questions

Short question: If I have class that impelemnts FactoryBean interface, how can I get
Long story below short question: How can I get Spring's NamedParameterJDBCTemplate join Hibernate's session?
Question in title... In short - I have a WCF service exposing operations that
Short question: Do any of MS's built in Data Objects support INotifyPropertyChanged? Long explination:
Short question: Is the parent of an entity group included in that entity group
Short question. How do you go about transposing UML diagrams into code? The class
This is a short question. At some point my thread understand that it should
Short question: How do I automatically detect whether a CSV file has headers in
Here is my question. I have this model one [Event] has multiple [Day] and
Ok, the short version is that I have a Linq entity from a LinqDataSourceUpdateEventArgs

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.