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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:16:34+00:00 2026-05-16T10:16:34+00:00

I have designed a class which is basically nothing but an object which stores

  • 0

I have designed a class which is basically nothing but an object which stores a large number of properties of a piece of data. I have implemented IComparable in the class. Objects of the class are instantiated and stored in a List.

There is an added level of complexity in that certain fields of the object determine on which fields I sort (there is a hierarchy) The hierarchy is thus:

  • 1) Name (defined at instantiation)
  • 2) Product (defined at instantiation)
  • 3) NetGroup (defined
    post-instantiation, after initial
    creation of the list, I iterate back
    through, perform a calculation, and
    set the group.)
  • 4) Date (defined at instantiation)

There are several flags (bool fields) which determine if two of the above are used in the sort hierarchy.

  • 5) AllowProductGroupingInd (defined
    at instantiation)
  • 6) AllowDateGroupingInd (defined at
    instantiation)

The performance of the sort on a relatively small list (n = 1000) is poor, generally about 500 ms.

I’m unsure if I’ve implemented my comparer properly.
My method looks like this:

    public int CompareTo(Exposure rfpe)
            {
                if (Name.CompareTo(rfpe.Name) != 0)
                    return Name.CompareTo(rfpe.Name);
                else
                {
                    if (AllowProductGroupingInd == false)
                    {
                        if (ProductId.CompareTo(rfpe.ProductId) != 0)
                            return ProductId.CompareTo(rfpe.ProductId);
                    }

                    if (NetGroup.CompareTo(rfpe.NetGroup) != 0)
                        return NetGroup.CompareTo(rfpe.NetGroup );
                    else if (AllowDateGroupingInd == false)
                    {
                        if (Date.CompareTo(rfpe.Date) != 0)
                            return Date.CompareTo(rfpe.Date);
                        else
                            return 0;
                    }

                    return 0;
                }

            }

I am using C# 3.0 so I cannot use LINQ. Is this a reasonable implementation of what I want to accomplish? Is there a more elegant solution? It seems to me I may be using too many conditionals, but I’m unsure how to get around that.

  • 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-16T10:16:35+00:00Added an answer on May 16, 2026 at 10:16 am

    You appear to be double calling each of the subsidiary CompareTo methods, the first one being most likely the main culprit performance-wise.

    int nameCompare = Name.CompareTo(rfpe.Name);
    
    if (nameCompare != 0)
       return nameCompare;
    else
       ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have designed a class containing some information about a given object which will
I have a helper class designed to get data from Core Data and pass
I have designed an ASP.NET page which create graphs. I have written a class
The preamble: I have designed a strongly interfaced and fully mockable data layer class
I have a designed a Class which acts as if it is a CD,
I have a class which implements IHttpHandler that is designed to handle image resize
I am working on a class library using C#. I have designed 3 main
I have some C# class libraries, that were designed without taking into account things
I have designed this gui in netBeans which has a canvas , a couple
I have designed a custom section handler before but I'm faced with a problem

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.