Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Delegate1=新Delegate1(乐趣)和Delegate1=乐趣之间的差异;_C#_Delegates - Fatal编程技术网

C# Delegate1=新Delegate1(乐趣)和Delegate1=乐趣之间的差异;

C# Delegate1=新Delegate1(乐趣)和Delegate1=乐趣之间的差异;,c#,delegates,C#,Delegates,我有一点怀疑,在初始化委托时,我们通常使用=。以下案例之间的区别是什么。两者的工作原理相同 public delegate void sam(int i); //variant 1 s = new sam(fun); //variant 2 s = fun; 两者之间没有区别。两者都生成相同的IL代码,但第二个变体需要C#2.0及更新版本。考虑以下代码: sam s = new sam((i) => { }); s = (i) => { }; 他们两个都是一样的

我有一点怀疑,在初始化委托时,我们通常使用
=
。以下案例之间的区别是什么。两者的工作原理相同

public delegate void sam(int i); 

//variant 1    
s = new sam(fun);

//variant 2
s = fun;

两者之间没有区别。两者都生成相同的IL代码,但第二个变体需要C#2.0及更新版本。

考虑以下代码:

sam s = new sam((i) => { });

s = (i) => { };
他们两个都是一样的