我似乎无法得到我的头。
我有以下几点:使用数组排序列表<object>
private String[] PREFERED = new String[] { "37", "22", "18" };
private List<Stream> library;
public class Stream
{
public String ID { get; set; }
public String URL { get; set; }
public String Description { get; set; }
public String Type { get; set; }
}
而且我想用PREFERED
字符串数组排序的List<Stream>
命名为library
,使我的结果将是library
用下面的命令:35
,22
,18
,...
library = library.OrderBy(o => Array.IndexOf(PREFERED, o.ID)).ToList();
但我没有得到预期的结果...
JSON
[{"ID":"44","URL":null,"Description":".webm (854x480)","Type":".webm"},
{"ID":"35","URL":null,"Description":".3gp (854x480)","Type":".3gp"},
{"ID":"43","URL":null,"Description":".webm (640x360)","Type":".webm"},
{"ID":"34","URL":null,"Description":".flv (640x360)","Type":".flv"},
{"ID":"18","URL":null,"Description":".mp4 (480x360)","Type":".mp4"},
{"ID":"5","URL":null,"Description":".flv (400x240)","Type":".flv"},
{"ID":"36","URL":null,"Description":".flv (400x240)","Type":".flv"},
{"ID":"17","URL":null,"Description":".3gp (176x144)","Type":".3gp"}]
你会得到什么结果? – Andrew
第一个元素('37'和'35')的差异是否也存在于您的代码中? – Douglas
我相信这应该工作给所有的ID保证存在,但是如果没有找到'IndexOf'返回减1,这会撞到一个不存在的ID到列表的前面。 –