OrderBy
and OrderByDescending
don't change the caller, they return new IQueryable
/IEnuemrable
instead. You have to assign it back to another (or the same) variable. Otherwise calling them has no sense.
Because you're using List<T>
you have to add additional ToList()
call to make it compile and work:
if (orderBy == "Identifier")
{
if (direction == "ASC")
results = results.OrderBy(x => x.Identifier).ToList();
else
results = results.OrderByDescending(x => x.Identifier).ToList();
}
// (...)
or you can use List<T>.Sort
instead:
if (orderBy == "Identifier")
{
if (direction == "ASC")
results.Sort((x1, x2) => x1.Compare(x2));
else
results.Sort((x1, x2) => x2.Compare(x1));
}