I would like to sort the ‘weeks’ below. The ‘InvalidCast Exception’ tells me I’m not even close (no matter what I’ve thrown at it).
sortedWeeks looks good in the debugger…
How do I get it back into the class?
I don’t actually need the original Weeks class as it will be run through the JavaScriptSerializer … though I would like to know how to sort this class…
Weeks theData = new Weeks();
// pretend its now full of data and I need the weeks sorted on number
var sortedWeeks = theData.weeks.OrderBy(x => x.number);
theData.weeks = sortedWeeks; // <--- How do I cast this??
public class Weeks
{
private List<Week> _weeks = new List<Week>();
public List<Week> weeks
{
get { return _weeks; }
set { _weeks = value; }
}
}
public class Week
{
public string week { get; set; }
public string file { get; set; }
public int number { get; set; }
}
1 Answer