gpt4 book ai didi

c# - 运算符 '=>' 在 C# 中是什么意思?

转载 作者:太空狗 更新时间:2023-10-29 20:53:51 24 4
gpt4 key购买 nike

此语句中的“=>”表示什么?

del = new SomeDelegate(() => SomeAction());

上面的声明和这个一样吗?

del = new SomeDelegate(this.SomeAction);

谢谢。

最佳答案

基本上它指定了一个匿名函数,该函数不带参数调用 SomeAction。所以是的,它们在功能上是等价的。虽然不平等。使用 lambda 更等同于:

del = new SomeDelegate(this.CallSomeAction);

其中 CallSomeAction 定义为:

public void CallSomeAction()
{
this.SomeAction();
}

希望对您有所帮助!

关于c# - 运算符 '=>' 在 C# 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/574280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com