我想对下面的“周”进行排序。'InvalidCast Exception' 告诉我我什至没有接近(无论我向它抛出了什么)。
sortedWeeks 在调试器中看起来不错...
我如何让它回到课堂上?
我实际上并不需要原始的 Weeks 类,因为它将通过 JavaScriptSerializer 运行......虽然我想知道如何对这个类进行排序......
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; }
}