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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:51:09+00:00 2026-06-05T15:51:09+00:00

I am setting the items which i want to Remove from list as null

  • 0

I am setting the items which i want to Remove from list as null and then sorting list through IComparable method CompareTo so that null items would be at the top … then using RemoveRange function on list but unable to so so … i see no problem in following code:

      try
      {
          foreach (Invoice item in inv)
          {
              if (item.qty == 0)
              {
                  item.CustomerName = null;
                  item.qty = 0;
                  i++;
              }
          }
          inv.Sort();
          inv.RemoveRange(0, i);
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.Message);

}

        #region IComparable<Invoice> Members

    public int CompareTo(Invoice other)
    {
        return this.CustomerName.CompareTo(other.CustomerName);
    }

    #endregion

error occurs at inv.RemoveRange(0,i); saying that :Failed to compare two elemets in array

Why is it so??

  • 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-05T15:51:11+00:00Added an answer on June 5, 2026 at 3:51 pm
    public int CompareTo(Invoice other)
        {
        if (other == null || other.CustomerName == null) return 1;
        if (this.CustomerName == null) return -1;
    
        return this.CustomerName.CompareTo(other.CustomerName);
        }
    

    or

    public int CompareTo(Invoice other)
            {
            //if other Invoide is null, instance is bigger.
            if (other == null) return 1;
            if (this.CustomerName == null) {
               //if both CustomerName are null, instance equals other. Of only instance CustomerName is null, other is bigger.
               return other.CustomerName == null ? 0 : -1;
            }
            //if other.CustomerName is null (and instance.CustomerName is not null), instance is bigger.
            if (other.CustomerName == null) return 1;
    
            //both CustomerName are not null, call basic string.CompareTo
            return this.CustomerName.CompareTo(other.CustomerName);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method which refreshes a list view by re-setting the adapter of
I have like 20 items which the user can pick from. Now I want
How to enumerate items of Spark List component after setting dataProvider property? I mean
I've been having some issues setting up a list of items and moving them
I have a dialog application in which I want to have clickable menu items
I have a Canvas in a Flex application which has items inside it that
We have a scenario where we want to display a list of items and
Right now when i'm setting publishing restrictions for items in Sitecore that get rendered
i have this method on which i retrieve first a Varien_Data_Collection and then I
Assume I have a such json setting: { page:1, items:[ { name: 'item1', id:1

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.