相关疑难解决方法(0)

即使签名匹配,也无法将一种类型的委托分配给另一种类型

我的病态好奇让我想知道为什么以下失败:

// declared somewhere
public delegate int BinaryOperation(int a, int b);

// ... in a method body
Func<int, int, int> addThem = (x, y) => x + y;

BinaryOperation b1 = addThem; // doesn't compile, and casting doesn't compile
BinaryOperation b2 = (x, y) => x + y; // compiles!
Run Code Online (Sandbox Code Playgroud)

c# lambda delegates type-conversion func

11
推荐指数
2
解决办法
3963
查看次数

标签 统计

c# ×1

delegates ×1

func ×1

lambda ×1

type-conversion ×1