Expression<func<t,tresult>> and Func<t,tresult>

Source: Internet
Author: User

1.expression<func<t,tresult>> is an expression

Use LambdaExpression to build an expression tree            expression<func<int, int, int, int>> expr = (x, y, z) = = (x + y)/z;            Console.WriteLine (Expr.compile () (1, 2, 3));

Https://msdn.microsoft.com/zh-cn/library/system.linq.expressions.expression (v=vs.100). aspx

https://msdn.microsoft.com/zh-cn/library/bb335710 (v=vs.100). aspx

2.func<t, Tresult> commissioned

Encapsulates a method that has a parameter and returns the type value specified by the TResult parameter.
Public delegate TResult Func<in T, out tresult> (t Arg)
Type parameter
In T
The parameter type of the method encapsulated by this delegate.
The type parameter is contravariant. That is, you can use a specified type or a lower-derived type. For more information about covariance and contravariance, see Covariance and contravariance in generics.
Out TResult
The return value type of the method encapsulated by this delegate.
The type parameter is covariant. That is, you can use the specified type or a higher-derived type. For more information about covariance and contravariance, see Covariance and contravariance in generics.
Parameters
Arg
Type: T
The parameters of the method encapsulated by this delegate.
return value
Type: TResult
The return value of the method encapsulated by this delegate.

  String mid = ", middle part,";                Anonymous notation func<string, string> Anondel = delegate (string param) {param + = mid;                param + = "and this is added to the string.";            return param;            };                    λ expression func<string, string> lambda = param = {param + = mid;                    param + = "and this is added to the string.";                return param;            };                     λ expression (shaping) func<int, int> lambdaint = Paramint + = {Paramint = 5;                return paramint;            }; Lambda expression with two arguments func<int, int, int> twoparams = (x, y) + = {return x                *y;            };            MessageBox.Show ("anonymous method:" +anondel ("Start of String"));         MessageBox.Show ("Lambda expressions:" + lambda ("lambda expression"));   MessageBox.Show ("λ-expression (shaping):" + lambdaint (4).            ToString ()); MessageBox.Show ("lambda expression with two parameters:" + twoparams (10, 20). ToString ());

Expression<func<t,tresult>> and Func<t,tresult>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.