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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:23:52+00:00 2026-05-25T14:23:52+00:00

I am trying to figure out a way to correctly sort a bunch of

  • 0

I am trying to figure out a way to correctly sort a bunch of different arraylists.
I am publishing content articles and every value [0] in an arraylist will relate to every other value [0]. and so on. Each element makes up the collective parts of a complete content item.

Now, the last element, popularity, is the amount of clicks an item has received. How do I
do a sort of the content items based on popularity without mixing up the html for each article?

*EDIT I am limited by the .NET 2.0 Framework at Work*

Below is the code… thanks.

public class MultiDimDictList : Dictionary<string, ArrayList> { } 

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);
  • 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-25T14:23:53+00:00Added an answer on May 25, 2026 at 2:23 pm

    If you use the following code you can convert your existing dictionary of arraylists into a collection of Dictionaries and thus allowing a simple sort using Linq OrderBy

    // Get the shortest arraylist length (they should be equal this is just a paranoia check!)
    var count=myDicList.Values.Min(x=>x.Count); 
    // Get the collection of Keys
    var keys=myDicList.Keys;
    // Perform the conversion
    var result=Enumerable.Range(0,count).Select(i=>keys.Select(k=>new {Key=k,Value=myDicList[k][i]}).ToDictionary(x=>x.Key,x=>x.Value)); 
    
    var sorted=result.OrderByDescending(x=>x["popularity"]).ToList()
    

    — EDIT VERSION FOR .NET 2.0

    First you need a comparer class

    class PopularityComparison : IComparer<Dictionary<string,object>> {
        private bool _sortAscending;
    
        public PopularityComparison(bool sortAscending) {
            _sortAscending = sortAscending;
        }
    
        public int Compare(Dictionary<string, object> x, Dictionary<string, object> y) {
            object xValue = x["popularity"];
            object yValue = y["popularity"];
    
            // Sort Ascending
            if (_sortAscending) {
                return Comparer.Default.Compare(xValue, yValue);
            } else {
                return Comparer.Default.Compare(yValue, xValue);
            }
    
        }
    }
    

    Then you can use the following code

    // Get the shortest arraylist length (they should be equal this is just a paranoia check!) 
    // Replacement for min 
    int count = int.MaxValue;
    foreach (ArrayList a in myDicList.Values) if (a.Count < count) count = a.Count;
    // Get the collection of Keys 
    Dictionary<string, ArrayList>.KeyCollection keys = myDicList.Keys;
    // Perform the conversion 
    List<Dictionary<string, object>> result = new List<Dictionary<string, object>>(count);
    for (int i = 0; i < count; i++) {
      Dictionary<string, object> row = new Dictionary<string, object>(keys.Count);
      foreach (string key in keys) row.Add(key, myDicList[key][i]);
      result.Add(row);
    }
    

    And then finally to sort in ascending popularity order

    result.Sort(new PopularityComparison(true));
    

    or Descending order

    result.Sort(new PopularityComparison(true));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out some way to get actual time via JavaScript,
I'm trying to figure out a way of how to be able to assign
I am trying to figure out my way through c89 and now I ma
I am trying to figure out a way to cut out a certain region
I'm trying to figure out a way to limit the dragging option of the
I am trying to figure out a way for somehow fetching the all the
I'm trying to figure out a way to re-use the validation rules of Yii's
I am trying to figure out a way to pre-process few things before my
I'm trying to figure out a way to use tar+pipes on a Ubuntu Server
I'm trying to figure out a way to find out which files were affected

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.