简体   繁体   English

C#中的委托定义

[英]Delegate definition in C#

Assuming I have the following delegate: 假设我有以下代表:

public delegate int TestD(int p);

Is there any difference between 之间有什么区别

TestD del = MyMethod;

and

TestD del = new TestD(MyMethod);

No, there is no difference: starting with C# 2.0, you can specify delegates using a method group . 不,没有区别:从C#2.0开始,您可以使用method group指定委托。

Note: In an unlikely case that you need 1.0 compatibility, the second syntax would be your only option. 注意:在不太可能的情况下,您需要1.0兼容性,第二种语法将是您唯一的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM