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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:21:42+00:00 2026-05-12T12:21:42+00:00

Say you have two different classes where each have their own implementation of Equals;

  • 0

Say you have two different classes where each have their own implementation of Equals; which one is used? What if only one of them have one? Or none of them? Are any of the following lines equivalent?

object .Equals( first, second )
first .Equals( second )
second .Equals( first )

I’m guessing that the first two might be equivalent, but I don’t really have a clue.

What does it really 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. Editorial Team
    Editorial Team
    2026-05-12T12:21:43+00:00Added an answer on May 12, 2026 at 12:21 pm

    Basically it does three things:

    • Check for reference equality (return true if so)
    • Check for reference nullity (return false if either value is null; by now the null == null case has been handled)
    • Check for value equality with first.Equals(second)

    The ordering shouldn’t matter if both values have well-behaved equality implementations, as equality should be implemented such that x.Equals(y) implies y.Equals(x). However, the offline documentation I’ve got installed does state that first.Equals(second) (or objA.equals(objB) to use the real parameter naming) is specified. The online documentation doesn’t mention this, interestingly enough.

    Just to make all of this concrete, the implementation could look like this:

    public static bool Equals(object x, object y)
    {
        if (x == y) // Reference equality only; overloaded operators are ignored
        {
            return true;
        }
        if (x == null || y == null) // Again, reference checks
        {
            return false;
        }
        return x.Equals(y); // Safe as we know x != null.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say we have two classes, Foo and Foo Sub, each in a different
I have an Interface lets say ISendOut which I've inherited two different classes from
Say If i have two classes, in each class is a different JFrame, e.g
Lets say there are two pages with two different html elements which have the
I have an interface implemented by two different classes. Then, how can I say
Say I have two different cpp files. Both declare classes with the same name,
How would one go about ordering two different classes? So say there's Class1 and
I have got two classes, one a subclass of the other (say Animal and
Let's say you have two different categories of users with different profiles: one for
Say I have two classes, in two different headers, called: class TestA { public:

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.