当前位置:网站首页>C# Lambda

C# Lambda

2022-06-24 08:04:00 Kenight_

Definition :Lambda The expression is an anonymous function , Is a way to simplify anonymous methods

Basic form x => x * x ,=> It's the operator , On the left is the parameter , On the right is the expression ( Or method implementation code )

Example :

void Start()
    {
        // Func  Is predefined  delegate  The last parameter of the generic is the return value 
        Func<int, int, string> f = (x, y) =>
        {
            int i = x * y;
            return i.ToString();
        };

        print(f(2, 5));
    }

Parameters

If there are multiple parameters to use () , One hour can be omitted

expression

If there's only one statement , Omission {} and return , Such as x => 2 * x

Multiline statements must be added {} and return

原网站

版权声明
本文为[Kenight_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206240219094536.html