I am relatively new to LINQ and don't know how to do an Order By. I have an IEnumerable list of myObject and want to do something like select first myObject from myObjectList order by myObject.id asc
How can I accomplish this? Thanks
Ascending is the default order by direction.
var query = from myObject in myObjectList
orderby myObject.id
select myObject;
Object o = query.FirstOrDefault();
If you want descending, you will want to use orderby myObject.id descending
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With