I have a small doubt, while initializing delegates we usually use =
. What is the difference between the cases below. Both Work same.
public delegate void sam(int i);
//variant 1
s = new sam(fun);
//variant 2
s = fun;
I have a small doubt, while initializing delegates we usually use =
. What is the difference between the cases below. Both Work same.
public delegate void sam(int i);
//variant 1
s = new sam(fun);
//variant 2
s = fun;
There is no difference between both of them. Both generate the same IL code but the second variant needs C# 2.0 and newer.
Consider this code:
sam s = new sam((i) => { });
s = (i) => { };
Both of them is same.