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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:19:36+00:00 2026-05-25T15:19:36+00:00

I am trying to refactor the below code for the 2.0 framework (required at

  • 0

I am trying to refactor the below code for the 2.0 framework (required at work). The below code was kindly provided per a previous post in which I was trying to figure out how to sort a dictionary of arraylists. This is a bit of a tangent from that discussion. Below is the code:

 MultiDimDictList myDicList = new MultiDimDictList();
myDicList.Add("fly", a_fly);
myDicList.Add("img", a_img);
myDicList.Add("bar", a_bar);
myDicList.Add("meter", a_meter);
myDicList.Add("block", a_block);
myDicList.Add("popularity", a_pop); 

List<int> OrderedByPopularity = new List<int>();
ArrayList popList = myDicList["popularity"];

for (int i = 0; i < popList.Count; ++i)
{
    OrderedByPopularity.Add(i);
}

OrderedByPopularity.Sort((i1, i2) => 
{ 

    return popList[i2].CompareTo(popList[i1]); 

});

When I try to run the above code, the bottom-most logic is giving me problems – namely, that “CompareTo” is not recognized. I have done some reading up on this and it looks like I have to implement IComparable to get this to work but I could use some help / suggestions here. Where should I be implementing IComparable? Also, the compiler is also telling me to use “delegate” for my .Sort method. Am i right that it should look like: .Sort(delegate(int i1, int i2) => ?

Thanks for your 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-25T15:19:37+00:00Added an answer on May 25, 2026 at 3:19 pm

    IComparable is an interface that you implement on a class that you want to be able to be…comparable. The Sort method knows how to work with the IComparable interface right off the bat. So, it follows that if you want to sort using the Sort method, your class must implement IComparable Otherwise, when you call CompareTo on your class, how would you expect the sorting algorithm to know how your class logically sorts?

    That is some background on how IComparable works, but it doesn’t look like it is the problem here unless I am misreading. It looks like you are trying to:

    1. Fill OrderedByPopularity with a bunch of integers.
    2. Sort the integers.

    If you really want to sort the integers in your list, you should just need to use

    (i1, i2) => 
    { 
        return i1.CompareTo(i2); 
    }
    

    the int (which is the type of element in the List) already has CompareTo on it.

    Does this answer the question?

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

Sidebar

Related Questions

So I'm trying to refactor some code which creates JDBC objects in a loop
I'm trying to refactor some slow running code which writes XML using nested loops
I am trying to refactor a piece of code which seems easily refactorable but
I am trying to refactor out my application a little bit to keep it
I have the following code for adding to/extracting from Zip. I'm trying to refactor
Im trying to refactor my application (with 1000+ lines of GUI code) to an
I am trying to refactor some code while leaving existing functionality in tact. I'm
I'm trying to refactor some code and move some of my before_filter's from the
I am trying to refactor a working code. The code basically derives an interface
I'm trying to refactor my sinatra code to separate my main file into separate

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.