How can I define a lambdaexpression that I want to use in a linq query as a variable?
For example when sorting a generic list by different properties of the listitems:
IList<SampleClass> list = new List<SampleClass>();
// Populate list
...
list.OrderBy(sampleclass => sampleclass.property1);
list.OrderBy(sampleclass => sampleclass.property2);
I would like to define the lambda expression (sampleclass => sampleclass.property1) in a variable and call:
// ??? define expression in a variable ???
Expression expression = sampleclass => sampleclass.property1;
// Sort list by variable expression
list.OrderBy(expression);
Thanks in advance Tobi