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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:52:25+00:00 2026-05-30T20:52:25+00:00

I have a very simply question regarding IEquatable. Given the following basic classes: public

  • 0

I have a very simply question regarding IEquatable. Given the following basic classes:

public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public SalaryInformation AnnualSalaryInformation { get; set; }

    }

    public class SalaryInformation
    {
        public string TaxCode { get; set; }
        public string SalaryBand { get; set; }
        public BankInformation AccountInfo { get; set; }
    }

    public class BankInformation
    {
        public string SortCode { get; set; }
        public string AccountNumber { get; set; }
    }

If I wanted to compare to Person objects for equality how would I go about it? If I implement the IEquatable interface on the the Person class, will it automatically cascade down to any objects within that class or do I have to explicitly implement the interface on all the classes?

If I do have to implement the interface on all the classes, are there any particular ‘gotchas’ I should look out for, when comparing an instance of Person to another instance of Person?

  • 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-30T20:52:27+00:00Added an answer on May 30, 2026 at 8:52 pm

    Equality between objects can take many forms, depending on what exactly you need. To answer your question:

    No, just because Person implements IEquatable doesn’t mean that SalaryInformation implements IEquatable. The relationship between Person and SalaryInformation is a composition and compositions don’t care about interface implementation.

    The Equals implementation of Person thus depends on when you consider two persons to be the same:

    • Are they the same if they share the same first and last name?
    • Are they the same if they have the same SalaryInformation, too?

    Also, if you want to be able to compare objects for equality there are a few guidelines to remember:

    1. Equality is an equivalence relation, i.e. it is
      a. reflexive,
      b. symmetric and
      c. transitive.
    2. Remember that null isn’t equal to any object.
    3. Always override GetHashCode too.

    If you got the hang of it, it’s not hard to do right, but if you never done it all sorts of issues can arise.

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

Sidebar

Related Questions

Very simply put: I have a class that consists mostly of static public members,
This is a question regarding a very simple construction - I have the following
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
Let's say we have very simple Java class MyClass . public class MyClass {
I have a very simple question regarding BSTs. I have seen multiple definitions of
All, I have a very general question regarding a future project. I need to
I have a very simple question. I want to test whether a particular port
I am learning LINQ and have a very simple question that I think will
I have a very simple Office utility question. Open Microsoft word (2003 or 2007),
I have what may be a very simple question. I want to process a

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.