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.