0
我有一個用於排序對象列表的現有代碼。轉換通用收集排序以利用Linq
productsList.Sort(
delegate(Product p1, Product p2)
{
int result = p1.StartDatetime.CompareTo(p2.StartDatetime);
if (result == 0)
{
if (p1.SomeId == p2.SomeId)
{
result = 0;
}
else if (p1.SomeId == null)
{
result = -1;
}
else if (p2.SomeId == null)
{
result = 1;
}
}
return result;
});
我有一種感覺,這可以通過替換它被簡化:
productsList = productsList
.OrderBy(p => p.StartDatetime)
.ThenBy(p => p.SomeId)
.ToList();
我是在我的假設是正確的?