0

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;
Michael Mairegger
  • 6,833
  • 28
  • 41
keerti_h
  • 383
  • 2
  • 13

2 Answers2

1

There is no difference between both of them. Both generate the same IL code but the second variant needs C# 2.0 and newer.

Michael Mairegger
  • 6,833
  • 28
  • 41
1

Consider this code:

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

s = (i) => { };

Both of them is same.