I have an existing bit of code for sorting a list of objects.
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;
});
I have a feeling that this can be simplified by replacing it with:
productsList = productsList
.OrderBy(p => p.StartDatetime)
.ThenBy(p => p.SomeId)
.ToList();
Am I correct in my assumption?