Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This would be much easier if you had a list of article objects, each of which contained properties for <code>fly</code>, <code>img</code>, <code>bar</code>, <code>popularity</code>, etc. But if you really have to store things using this inside-out approach, then the only way you can sort the content items based on popularity is to create another array (or list) to hold the order.</p> <p>Create a new list and populate it with sequential indexes:</p> <pre><code>List&lt;int&gt; OrderedByPopularity = new List&lt;int&gt;(); ArrayList popList = myDicList["popularity"]; for (int i = 0; i &lt; popList.Count; ++i) { OrderedByPopularity.Add(i); } </code></pre> <p>Now you have a list that contains the indexes of the items in the popularity list. Now you can sort:</p> <pre><code>OrderedByPopularity.Sort((i1, i2) =&gt; return popList[i1].CompareTo(popList[i2]);); </code></pre> <p>But that gives you the least popular article first. If you want to reverse the sort so that <code>OrderedByPopularity[0]</code> is the most popular item:</p> <pre><code>OrderedByPopularity.Sort((i1, i2) =&gt; { return popList[i2].CompareTo(popList[i1]);}); </code></pre> <p>Really, though, you should look into restructuring your application. It's much easier to work with objects that have properties rather than trying to maintain parallel arrays of properties.</p> <p>If you have to do this in .NET 2.0, declare the <code>poplist</code> array at class scope (rather than method scope), and create a comparison method.</p> <pre><code>ArrayList poplist; void MyMethod() { List&lt;int&gt; OrderedByPopularity = new List&lt;int&gt;(); popList = myDicList["popularity"]; for (int i = 0; i &lt; popList.Count; ++i) { OrderedByPopularity.Add(i); } OrderedByPopularity.Sort(PopularityComparison); // ... } int PopularityComparison(int i1, int i2) { return ((int)popList[i2]).CompareTo((int)popList[i1]); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload