开发者

Sorting array of object by name (multi dimensional)

how can i sort a array of objects by name.

Example of how the array is constructed array:

     object[] o = new object[items.Count+(row-exists)];
     int i = 0;
     for(i=0; i<items.Count;i++)
     {
    XmlNode item = items[i];

    o[i] = new object[5];
    ((object[])o[i])[0] = Safe(item, "ows_Title");
    ((object[])o[i])[1] = S开发者_如何学Cafe(item, "ows_Column5");
    ((object[])o[i])[2] = ((string)Safe(item, "ows_Column7")).Trim(new char[] {'\''});
    ((object[])o[i])[3] = Convert.ToDouble(Safe(item, "ows_Column12"), provider);
    ((object[])o[i])[4] = Convert.ToDouble(Safe(item, "ows_Column9"), provider);
}

i want the 'o' to be sorted based on the value of ((object[])o[i])[0] .

Thank you


I think I understand. The linq below should do what you require.

var sortedResult = o.OrderBy(x => ((object[])x)[0]).ToArray();

However, I would look at using a differt data structure. Can you create a new type to encapsulate what the second array represents? For example:

class MyObject
{
  Safe Title {get; set;}
  Safe Column5 {get; set;}
  String Column7 {get; set;}
  double Column9 {get; set;}
  double Column12 {get; set;}
}

You can then use a SortedList to store the new objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜