Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass Parameter on Linq Query

Tags:

c#

lambda

linq

Is it possible to pass the parameter after the period on a LINQ Query?

For example on this code:

objResultFinal = objResultFinal.OrderByDescending(x => x.[iwanttopassparameterhere]).ToList();

Is that possible? I want to declare after the "x." the string that I want to query.

like image 435
Willy David Jr Avatar asked Apr 28 '26 16:04

Willy David Jr


1 Answers

objResultFinal.OrderByDescending(s => s.GetType().GetProperty("PropertyName").GetValue(s, null));
like image 190
Radim Drtílek Avatar answered Apr 30 '26 06:04

Radim Drtílek