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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:23:20+00:00 2026-06-11T16:23:20+00:00

Ok, I have a simple IEnumerable<HtmlString> things and I want to divide it up

  • 0

Ok, I have a simple IEnumerable<HtmlString> things and I want to divide it up into four equal groups.

var quarter = things.OrderBy(t => t.Foo).Count() / 4;

should do the trick, but instead I get this funkiness:

Server Error in ‘/’ Application. At least one object must implement
IComparable. Description: An unhandled exception occurred during the
execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.

Exception Details: System.ArgumentException: At least one object must
implement IComparable.

Line 36: int quarter = things.OrderBy(t => t.Foo).Count() / 4;

Anyone know what the heck is going on here? Why would I need to implement IComparable to get a simple count?

  • 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-06-11T16:23:21+00:00Added an answer on June 11, 2026 at 4:23 pm

    My guess is that this is to do with lazy evaluation of LINQ’s OrderBy. For example, if you have:

    var things = unsortedThings.OrderBy(foo => foo.Bar);
    var quarter = things.Count() / 4;
    

    then if the foo.Bar properties can’t be compared with each other, that will throw exactly that exception.

    For example:

    using System;
    using System.Linq;
    
    class Foo {}
    
    class Program
    {
        public static void Main()
        {
            var foos = new[] { new Foo(), new Foo() };
            var ordered = foos.OrderBy(x => x);
            Console.WriteLine(ordered.Count());
        }
    }
    

    Output:

    Unhandled Exception: System.ArgumentException: At least one object must implement IComparable.
       at System.Collections.Comparer.Compare(Object a, Object b)
       at System.Linq.EnumerableSorter`2.CompareKeys(Int32 index1, Int32 index2)
       at System.Linq.EnumerableSorter`1.QuickSort(Int32[] map, Int32 left, Int32 right)
       at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
       at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
       at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
       at Program.Main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have: IEnumerable<Foo> foolist and i want to convert this to: IEnumerable<Bar> barlist is
I have a simple while loop IEnumerable<Foo> collection; while (!bc.IsCompleted) { collection = bc.Take();
Say I have this simple method: public IEnumerable<uint> GetNumbers() { uint n = 0;
I have simple JavaScript snippet: var obrazek = [{nazwa: "Sniadanie", wiek: 100, autor: "Alicja"},{nazwa:
To keep things simple, I have this class: public class Contact { public string
So I have simple tree: class MyNode { public MyNode Parent; public IEnumerable<MyNode> Elements;
I have a simple interface: public interface IReadOnlyList<T> : IEnumerable<T> { T this[int index]
I have a class which takes an IEnumerable constructor parameter which I want to
I have a simple XML, <S xmlns=\http://schemas.microsoft.com/winfx/2006/xaml/presentation\><H></H></S> I want to find all H nodes.
I have a simple table: ID | Value When I do this: var sequence

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.