注意:我知道之前的问题" LINQ的Expression.Quote方法的目的是什么?",但如果你继续阅读,你会发现它没有回答我的问题.
我明白所说的目的Expression.Quote()是什么.但是,Expression.Constant()可以用于相同的目的(除了Expression.Constant()已经使用的所有目的).因此,我不明白为什么Expression.Quote()需要.
为了证明这一点,我写了一个快速的例子,其中一个人习惯使用Quote(见标有感叹号的行),但我使用了Constant它,它同样有效:
string[] array = { "one", "two", "three" };
// This example constructs an expression tree equivalent to the lambda:
// str => str.AsQueryable().Any(ch => ch == 'e')
Expression<Func<char, bool>> innerLambda = ch => ch == 'e';
var str = Expression.Parameter(typeof(string), "str");
var expr =
Expression.Lambda<Func<string, bool>>(
Expression.Call(typeof(Queryable), "Any", new Type[] { typeof(char) },
Expression.Call(typeof(Queryable), "AsQueryable",
new Type[] { typeof(char) }, str),
// …Run Code Online (Sandbox Code Playgroud)