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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:11:29+00:00 2026-05-21T10:11:29+00:00

1) Are the reasons why IEqualityComparer<T> was introduced: a) so we would be able

  • 0

1) Are the reasons why IEqualityComparer<T> was introduced:

a) so we would be able to compare objects (of particular type) for equality in as many different ways as needed

b) and by having a standard interface for implementing a custom equality comparison, chances are that much greater that third party classes will accept this interface as a parameter and by that allow us to inject into these classes equality comparison behavior via objects implementing IEqualityComparer<T>

2) I assume IEqualityComparer<T> should not be implemented on type T that we’re trying to compare for equality, but instead we should implement it on helper class(es)?

Thank you

  • 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-21T10:11:30+00:00Added an answer on May 21, 2026 at 10:11 am

    I’m doubtful that anyone here will be able to answer with any authority the reason that the interface was introduced (my guess–and that’s all it is–would be to support one of the generic set types like Dictionary<TKey, TValue> or HashSet<T>), but its purpose is clear:

    Defines methods to support the comparison of objects for equality.

    If you combine this with the fact you can have multiple types implementing this interface (see StringComparer), then the answer to question a is yes.

    The reason for this is threefold:

    1. Operators (in this case, ==) are not polymorphic; if the type is upcasted to a higher level than where the type-specific comparison logic is defined, then you’ll end up performing a reference comparison rather than using the logic within the == operator.
    2. Equals() requires at least one valid reference and can provide different logic depending on whether it’s called on the first or second value (one could be more derived and override the logic of the other).
    3. Lastly and most importantly, the comparison logic provided by the type may not be what the user is after. For example, strings (in C#) are case sensitive when compared using == or Equals. This means that any container (like Dictionary<string, T> or HashSet<string>) would be case-sensitive. Allowing the user to provide another type that implements IEqualityComparer<string> means that the user can use whatever logic they like to determine if one string equals the other, including ignoring case.

    As for question b, probably, though I wouldn’t be surprised if this wasn’t high on the list of priorities.

    For your final question, I’d say that’s generally true. While there’s nothing stopping you from doing so, it is confusing to think that type T would provide custom comparison logic that is different from that provided on type T just because it’s referenced as an IEqualiltyComparer<T>.

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

Sidebar

Related Questions

For reasons that I would not like to discuss, our master database schema is
for reasons based on storabiligty I have the following objects in a XAML graph:
For logging and reporting reasons I create objects that have the class name and
For reasons beyond the scope of this post, I would like to verify in
For reasons beyond the scope of this post, I would like to verify in
For reasons of synchronizing between 2 different DBs used by different applications, I need
For what reasons would I want to make my project an OSGI bundle as
For reasons undisclosed, suppose I have many identical README.txt files in a few dozen
For specific reasons, I need to be able to display some values on the
For aesthetic reasons, I would like to use the same private key that I

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.