Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Sử dụng đệ quy, PrintNode () chức năng chứng minh rằng một cây biểu hiện là một cây số không hay nhiều cây biểu. Các cây biểu có được lưu trữ trong thuộc tính cơ thể của một biểu thức. Ngoài ra, các cây bao gồm cả một tài sản ExpressionType gọi là NodeType nơi ExpressionType là một enum đối với từng loại khác nhau của biểu. | Summary 4TÌ Using recursion the PrintNode function demonstrates that an expression tree is a tree of zero or more expression trees. The contained expression trees are stored in an Expression s Body property. In addition the expression tree includes an ExpressionType property called NodeType where ExpressionType is an enum for each different type of expression. There are numerous types of expressions BinaryExpression ConditionalExpression LambdaExpression the root of an expression tree MethodCallExpression ParameterExpression and ConstantExpression are examples. Each type derives from System.Linq.Expressions .Expression. Generally you can use statement lambdas interchangeably with expression lambdas. However you cannot convert statement lambdas into expression trees. You can express expression trees only by using expression lambda syntax. SUMMARY This chapter began with a discussion of delegates and their use as references to methods or callbacks. It introduced a powerful concept for passing a set of instructions to call in a different location rather than immediately when the instructions are coded. Following on the heels of a brief look at the C 2.0 concept of anonymous methods the chapter introduced the C 3.0 concept of lambda expressions a syntax that supersedes although doesn t eliminate the C 2.0 anonymous method syntax. Regardless of the syntax these constructs allow programmers to assign a set of instructions to a variable directly without defining an explicit method that contains the instructions. This provides significant flexibility for programming instructions dynamically within the method a powerful concept that greatly simplifies the programming of collections through an API known as LINQ for language integrated query. Finally the chapter ended with the concept of expression trees and how they compile into data that represents a lambda expression rather than the delegate implementation itself. This is a key feature that enables such libraries as LINQ .