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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:30:29+00:00 2026-05-31T02:30:29+00:00

I have a class Person , it implements Equals() method from IEquatable<Person> (also overrides

  • 0

I have a class Person, it implements Equals() method from IEquatable<Person> (also overrides Object.Equals method, lets ignore the GetHashcode() method for now)

class Person : IEquatable<Person>
{
    public string Name { get; set; }

    public bool Equals(Person other)
    {
        return this.Name == other.Name;
    }
    public override bool Equals(object obj)
    {
        var person = obj as Person;
        return person != null && person.Name == Name;
    }
}

Ok, lets start:

Person p1 = new Person() { Name = "a" };
Person p2 = new Person() { Name = "a" };

List<Person> lst1 = new List<Person>() { p1 };
List<Person> lst2 = new List<Person>() { p2 };

Lets talk about this line :

 bool b = lst1.SequenceEqual(lst2, EqualityComparer<Person>.Default);

I have a problem understanding this part :

EqualityComparer<Person>.Default

I’ve heard that EqualityComparer<Person>.Default will check if the class is implementing IEquatable – it will take the Equals(Person other) Method and not the Equals(object obj). it has the advantage of avoiding boxing

enter image description here
but

the Equals(Person other) will run with or withOUT EqualityComparer<Person>.Default
(because it’s implementing IEquatable)

So what Boxing are we talking about ? there isn’t !

The only time that Equals(object obj) will run is when :

bool b = lst1.SequenceEqual(lst2,EqualityComparer<Object>.Default);

But I’m a programmer! I’ll never Send an object when its actually a Person!

What am I missing? I’m having trouble understanding the benefit here of EqualityComparer<Object>.Default. Can someone please give me an example to prove me I’m wrong ?

  • 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-31T02:30:30+00:00Added an answer on May 31, 2026 at 2:30 am

    If you pass in null as the second parameter or if you don’t pass in a second argument at all (which is basically the same), the implementation of SequenceEquals will call EqualityComparer<T>.Default itself (decompile Enumerable to see this). That explains why you don’t see a difference whether you provide EqualityComparer<T>.Default or not.

    So in the end the second parameter only makes sense if you want to use an equality comparer other than EqualityComparer<T>.Default.

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

Sidebar

Related Questions

I have an simple class that I get from a webservice. public class person
If I have a class Person that implements Comparable (compares personA.height to personB.height ,
i have this in the server: class Person{...} and @Stateless public class HelloServiceBean implements
I have a class called Person - public class Person implements Nameable { private
Possible Duplicate: What does Serializable mean? I have class Person implements Serializable { }
I have an abstract class Person and and interface comparable, which is also used
Let's have a class Person . Person has a name and height. Equals and
I have a class Person for which I have to override the Equals and
I have a class Person which can have several Homes, each one with one
I have a class Person and a class Name. Name contains two Strings firstName

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.