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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:02:26+00:00 2026-05-19T03:02:26+00:00

Basically i have a container which implements IEquatable (sample shown below) public class ContainerClass

  • 0

Basically i have a container which implements IEquatable (sample shown below)

public class ContainerClass  : IEquatable<ContainerClass>
{
        public IEnumerable<CustomClass> CustomClass { get; set; }

        public override bool Equals(object obj) { ... }
        public bool Equals(ContainerClass other) { ... }
        public static bool operator ==(ContainerClass cc1, ContainerClass cc2) { ... }
        public static bool operator !=(ContainerClass cc1, ContainerClass cc2) { ... }
        public override int GetHashCode() { ... }
}

and a CustomClass which also implements IEquatable

public class CustomClass : IEquatable<CustomClass>
{
        public string stringone { get; set; }
        public string stringtwo { get; set; }

        public override bool Equals(object obj) { ... }
        public bool Equals(CustomClass other) { ... }
        public static bool operator ==(CustomClass cc1, CustomClass cc2) { ... }
        public static bool operator !=(CustomClass cc1, CustomClass cc2) { ... }
        public override int GetHashCode() { ... }
}

All this is working fine, so for example, the following works

IEnumerable<CustomClass> customclassone = new List<CustomClass>
    {
        new CustomClass { stringone = "hi" },
        new CustomClass { stringone = "lo" }
    };
IEnumerable<CustomClass> customclasstwo = new List<CustomClass>
    {
        new CustomClass { stringone = "hi" }
    };

var diff = customclassone.Except(customclasstwo);

ContainerClass containerclassone = new ContainerClass 
{
    CustomClass = customclassone.AsEnumerable()
};
ContainerClass containerclasstwo = new ContainerClass 
{
    CustomClass = customclasstwo.AsEnumerable()
};

var diff2 = containerclassone.CustomClass.Except(customclasstwo.CustomClass);

After this code both diff and diff2 when enumerated contain the expected results. However, if i then try

IEnumerable<CustomClass> oldCustom = oldContainerClass.CustomClass;
IEnumerable<CustomClass> newcustom = newContainerClass.CustomClass;
var exceptlist = oldCustom.Except(newcustom);

When i try to enumerate the exceptlist i get “At least one object must implement IComparable.”. The only difference between oldCustom and newCustom from the ones in the above working examples is the way they are populated. Anyone got any idea why this is happening?

  • 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-19T03:02:27+00:00Added an answer on May 19, 2026 at 3:02 am

    I suspect that you attempted to sort these contents of the ContainerClass.CustomClass. Due to the deferred execution, you don’t know there’s a problem until you iterate through it and Except() is just a red herring. CustomClass doesn’t implement the IComparable interface so the sort fails with that error. Your CustomClass should either implement the IComparable<T> interface or you should pass in an IComparer on your OrderBy().

    e.g.,

    oldContainerClass.CustomClass = someListOfSomeType.OrderBy(x => x.CustomClasss, myComparer)
                                                      .Select(x => x.CustomClass);
    

    Though it would help to see what exactly you assigned to these properties so we can give you a more precise reason.

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

Sidebar

Related Questions

Basically, I have a Container class called Employees which has in it an ArrayList.
I basically have a page which shows a processing screen which has been flushed
Basically I have the following class: class StateMachine { ... StateMethod stateA(); StateMethod stateB();
I have an EJB app. which basically has to execute a SQL query when
I have a class where each instance is basically of a bunch of nested
I have a class that implements IAuthorizationPolicy. I set up a custom Principal object
I have a view called send_confirmation email - which basically sends emails. I want
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp
I am looking in to ways to enable a site to basically have something
I would like to do the following. Basically have a stored procedure call another

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.