I can't seem to get my head around this.
I have the following:
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; }
}
And I would like to sort the List<Stream>
named library
using the PREFERED
String array so that my result would be the library
with following order: 35
,22
,18
,...
library = library.OrderBy(o => Array.IndexOf(PREFERED, o.ID)).ToList();
But I'm not getting the expected result...
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"}]