0

I'm trying to sort a list of objects that I'm getting from a database a field defined in the value of a string.

My first assumption was I may be able to do something like the following:

string sortField = "TimeCreated";
List<T> data = SomeMethodToFetchData();
data.Sort(e => e.[sortField]);

I now know this syntax is invalid, but I would still like to try and do something similar that would work for any sortField value and if the field doesn't exist throw an exception or something.

I've been searching for a good answer to this for a few days now and I'm finding it very difficult to find an answer.

Ryan Callahan
  • 115
  • 1
  • 11

0 Answers0