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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:27:41+00:00 2026-06-11T05:27:41+00:00

How do I sort a rectangle list by their area? Been looking into IComparable

  • 0

How do I sort a rectangle list by their area? Been looking into IComparable at msdn library, but can’t figure it out… I wrote this:

SortedL= new List<Rectangle>();
        int count1 = 0;
        int count3 = redovi;
        while (count1 < count3)
        {
            int count2 = 0;
            while (count2 < count3)
            {
                int x = Oblici[count1].Width;
                int y = Oblici[count1].Height;
                int z = Oblici[count2].Width;
                int w = Oblici[count2].Height;
                int area1 = x * y;
                int area2 = z * w;
                int a = area1.CompareTo(area2);
                if (a < 0)
                {
                    count1 = count2;
                    if (count2 < (count3 - 1))
                    {
                        count2++;
                    }
                    else break;
                }
                else if (a == 0)
                {
                    if (count2 < (count3 - 1))
                    {
                        count2++;
                    }
                    else break;
                }
                else if (a > 0)
                {
                    if (count2 < count3 - 1)
                    {
                        count2++;
                    }
                    else break;
                }
            }
            SortedL.Add(Oblici[count1]);
            Oblici.RemoveAt(count1);
            count3 = (count3 - 1);}}

And it works, but it’s pretty ugly, and I know there is an easier way…

  • 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-11T05:27:42+00:00Added an answer on June 11, 2026 at 5:27 am

    how about this, using lambda expression to create your own Comparer

    mylist.Sort((X, Y) => ((X.Height * X.Width).CompareTo(Y.Height * Y.Width)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to sort a coordinate list for a rectangle counterclockwise, and make the
I've got a collection (List<Rectangle>) which I need to sort left-right. That part's easy.
Sort of a methods/best practices question here that I am sure has been addressed,
what sort of conditions can we use for branching in jinja2? I mean can
I have a WPF datagrid and it works great but I notice some sort
I'm trying to paint a rectangle on my application in a red shade but
I have a list of objects like this: [ Rectangle(20, 30, 100, 200), //
I wanted to do a sort of animation where a rectangle would move..However, the
Basically, I'm doing some sort of image processing using a screen-sized rectangle made of
I'm looking for a way to generate a set of random sided, but regular,

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.