Reputation: 259
I have the following:
List<object> myList = new List<object>();
myList.orderBy(x => x.Date);
I need to order myList by date, but because it's a list of objects I'm having trouble re-ordering it.
I believe I can do this using IEnumerable:
IEnumerable<object> receivedData = new List<object>();
but I'm not sure how to order it. Any tips? Thanks!
Upvotes: 1
Views: 88
Reputation: 25056
You will need to cast it into the class you want. object
doesn't have a property called Date
. Your class does.
You can do this in a few ways, one way is using the as
keyword.
Upvotes: 1
Reputation: 60493
you may use reflection
var orderedList = myList
.OrderBy(x => x.GetType().GetProperty("Date").GetValue(x, null)).ToList();
Upvotes: 5