Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is preferable: delegate {} or () => {}

Tags:

c#

I was wondering today if there's any reason to prefer using delegate {} instead of () => {}, in the cases where you need an empty function.

Do you know any reason to prefer one over another?

like image 912
Liviu Trifoi Avatar asked Jun 17 '11 08:06

Liviu Trifoi


1 Answers

They're not the same thing.

Since delegate {} does not supply an argument list, it can be converted to a delegate that returns void and takes any number of arguments (except refand out parameters).

This is not the same as () => {}, which is explicitly declared as taking no argument.

like image 182
Frédéric Hamidi Avatar answered Oct 11 '22 16:10

Frédéric Hamidi