Please, read my comment to the question. I asked there: why do you want to evaluate lambda expression. You didn't answered. Nevertheless...
In a few words: lambda expression is nothing else than inline delegate!
Have a look here:
Func<T1, T2, TResult> Delegate[
^]
Exploring Lambda Expression in C#[
^]
Conclusion: you can use it even as a parameter of function.
See:
Dynamic Queries and LINQ Expressions[
^]
http://stackoverflow.com/questions/14297633/c-sharp-pass-lambda-expression-as-method-parameter[
^]
Example (works like a charm):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LinqDelegate
{
class Program
{
static void Main(string[] args)
{
List<Emp> empD = new List<Emp> { new Emp("a", 1),
new Emp("b", 2),
new Emp("c", 1),
new Emp("d", 4) };
Func<Emp, int, bool> predicate = (e, i) => e.Age==1;
var qry = empD.Where(predicate).Select(x => x);
foreach (var e in qry)
Console.WriteLine("{0} = {1}", e.Name, e.Age);
Console.ReadKey();
}
class Emp
{
private string sName = String.Empty;
private int iAge = 0;
public Emp(string _Name, int _Age)
{
sName = _Name;
iAge = _Age;
}
public string Name
{
get { return sName; }
set { sName = value; }
}
public int Age
{
get { return iAge; }
set { iAge = value; }
}
}
}
}
Result:
a = 1
c = 1