什么是表达式树?如何使用它们?为什么要使用它们? [英] What are Expression Trees, how do you use them, and why would you use them?

查看:200
本文介绍了什么是表达式树?如何使用它们?为什么要使用它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到了表达树的概念,我已经多次听到过.我只想了解表达式树的含义及其目的.

I just came across the concept of expression trees which I have heard multiple times. I just want to understand what is meant by an expression tree and its purpose.

如果有人还可以指导我进行简单的解释和使用示例,我会喜欢的.

I would love it if someone could also direct me to simple explanations and samples of use.

推荐答案

表达式树是一个包含表达式的数据结构,它基本上是代码.因此,它是一个树形结构,代表您可能在代码中进行的计算.然后,可以通过在一组数据上运行"表达式树来执行这些代码.

An Expression Tree is a data structure that contains Expressions, which is basically code. So it is a tree structure that represents a calculation you may make in code. These pieces of code can then be executed by "running" the expression tree over a set of data.

关于表达式树的一件好事是,您可以在代码中构建它们.也就是说,您可以用代码构建可执行代码(或一系列步骤).您还可以在执行代码之前通过用其他表达式替换表达式来修改代码.

A great thing about expression trees is that you can build them up in code; that is, you build executable code (or a sequence of steps) in code. You can also modify the code before you execute it by replacing expressions by other expressions.

表达式是函数委托,例如(int x => return x * x).

An Expression is then a function delegate, such as (int x => return x * x).

另请参见 http://blogs.msdn.com /b/charlie/archive/2008/01/31/expression-tree-basics.aspx

这篇关于什么是表达式树?如何使用它们?为什么要使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆