多个参数的Lambda表达式 [英] Lambda expression for multiple parameters

查看:134
本文介绍了多个参数的Lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到lambda表达式本质上是一种内联委托声明,以防止执行额外的步骤

I understand a lambda expression is in essence an inline delegate declaration to prevent the extra step

示例

delegate int Square(int x)
public class Program
{
   static void Main(String[] args)
   {
      Square s = x=>x*x;
      int result = s(5);
      Console.WriteLine(result); // gives 25
   }
}

一个人如何将Lambda表达式应用于多个参数 像

How does one apply Lambda expressions to multi parameters Something like

 delegate int Add(int a, int b)
 static void Main(String[] args)
 {
    // Lambda expression goes here
 }

如何使用Lambda表达式表达多个参数?

How can multi parameters be expressed using Lambda expressions?

推荐答案

您必须了解 Func 行为,其中最后一个参数始终是 output result

You must understand the Func behavior, where the last parameter is always the output or result

Func< 1,2,outPut>

Func<1, 2, outPut>

Func<int, int, int> Add = (x, y) => x + y;

Func<int, int, int> diff = (x, y) => x - y;

Func<int, int, int> multi = (x, y) => x * y;

这篇关于多个参数的Lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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