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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:06:04+00:00 2026-05-20T13:06:04+00:00

Hi I have had to use interfaces before but ive been told i need

  • 0

Hi I have had to use interfaces before but ive been told i need to implement icomparable in this instance. see below:

internal class doorItem : IComparable
{
    public int CompareTo(doorItem other)
    {
        // The temperature comparison depends on the comparison of the
        // the underlying Double values. Because the CompareTo method is
        // strongly typed, it is not necessary to test for the correct
        // object type.
        return GetNumber(productSize).CompareTo(GetNumber(other.productSize));
    }
    public string variations { get; set; }
    public double pricerange { get; set; }
    public string viewDetailsLink { get; set; }
    public string height { get; set; }
    public string width { get; set; }
    public string productSize { get; set; }
    public string productImage { get; set; }
    public int countItemsOnSale { get; set; }
    public string optionFor35Product { get; set; }
    private int GetNumber(string str)
    {
//this method gets the int out of the string
        int length = str.Length;
        string output = String.Empty;
        int test = 0;
        bool err = false;

        for (int i = 0; i <= length; i++)
        {
            try
            {
                test = Convert.ToInt32(str.Substring(i, 1));
            }
            catch
            {
                err = true;
            }

            if (!err)
                output += str.Substring(i, 1);
            else
                break;
        }

        return Convert.ToInt32(output);
    }
}

above is the class i have created, door sizes are returned like this: 4dr, 5dr, 6dr etc.. then the getnumber method gets the int out of the string.

i have a generic list in of my custom class in the main method like this:

List<doorItem> d = new List<doorItem>();

i cant work out how to order this list by door size…. PLEASE HELP

  • 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-20T13:06:04+00:00Added an answer on May 20, 2026 at 1:06 pm

    It’s easiest to do this using LINQ. Then you don’t even need to implement IComparable.

    var sortedList = doorList.OrderBy( d => d.GetNumber(d.productSize ).ToList();
    

    And make GetNumber public inside the doorItem class.

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

Sidebar

Related Questions

I'm very much a vb person, but have had to use this id number
I had asked a question similar to this before, but I have a new
I use Codesmith to create our code generation templates and have had success in
I started coding in C# and have never had the opportunity to use callbacks
We have had SharePoint where I work for a little while now, but we've
I have had to do this several times, usually when trying to find in
We have/had a phantom delay in our app. This was traced to the initialisation
I have recently had two telephone interviews where I've been asked about the differences
This is more of a design question that others may have had similar experience
I have always had a hard time understanding the real value of Interfaces when

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.