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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:30:01+00:00 2026-05-10T22:30:01+00:00

I have a Customer class. public class Customer { private string _id; private string

  • 0

I have a Customer class.

public class Customer {     private string _id;     private string _name;     // some more properties follow  

I am inheriting the EqualityComparer form MyEqualityComparer(of Customer).
This I am intending to use in LINQ queries.
MyEqualityComparer is intended for partial check between two objects.
If the customer.id and customer.name matches I treat the objects the equal.

public class MyComparer : System.Collections.Generic.EqualityComparer<Customer> {     public override bool Equals(Customer x, Customer y)     {         if (x.Id == y.Id && x.Name == y.Name)             return true;         else             return false;     }      public override int GetHashCode(Customer obj)     {         return string.Concat(obj.Id,obj.Name).GetHashCode();     }  } 

I referred to generating hashcode.
I am little unsure about concatenating strings and using that as a hashcode.
Is this safe and sound what I am trying to do ?

  • 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. 2026-05-10T22:30:01+00:00Added an answer on May 10, 2026 at 10:30 pm

    See this question on hashcodes for a pretty simple way to return one hashcode based on multiple fields.

    Having said that, I wouldn’t derive from EqualityComparer<T> myself – I’d just implement IEqualityComparer<T> directly. I’m not sure what value EqualityComparer<T> is really giving you here, other than also implementing the non-generic IEqualityComparer.

    A couple more things:

    • You should handle nullity in Equals
    • Your present Equals code can be simplified to:

      return x.Id == y.Id && x.Name == y.Name; 

    A fuller implementation of Equals might be:

    public override bool Equals(Customer x, Customer y) {     if (object.ReferenceEquals(x, y))     {         return true;     }     if (x == null || y == null)     {         return false;     }     return x.Id == y.Id && x.Name == y.Name; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think XXXUtils is the common way. Then you can… May 11, 2026 at 5:28 pm
  • Editorial Team
    Editorial Team added an answer function getCookie(N){ if(N=(new RegExp(';\\s*'+N+'=([^;]*)')).exec(';'+document.cookie+';')) return N[1] } we'll be using… May 11, 2026 at 5:28 pm
  • Editorial Team
    Editorial Team added an answer Key bindings are kept in the workspace folder, under the… May 11, 2026 at 5:28 pm

Related Questions

I'm trying to figure out the cleanest way to do this. Currently I have
Do you have a common base class for Hibernate entities, i.e. a MappedSuperclass with
I need advice on how to return a limited set of data from an
Is it possible to search for an object by one of its properties in

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.