How do anonymous methods omit the parameter list?

I read this in the MSDN documentation on anonymous methods (C # Programming Guide) , but I don't understand the part where the parameter list is omitted. It says:

In one case, an anonymous method provides functionality not found in lambda expressions. Anonymous methods allow you to omit the parameter list. This means that an anonymous method can be converted to delegates with different signatures. This is not possible with lambda expressions.

Could you give an example of skipping the parameter list for an anonymous method?

+5
source share
1 answer

, - . , , - . , , 2- integer :

Func<int, int, int> func = delegate(int x, int y)
                           {
                                return x + y;
                           };

-, :

Func<int, int, int> func2 = (x,y) => x + y;

-. , :

Action act = () => Console.WriteLine("hello world");

, - , , . .

+3

Source: https://habr.com/ru/post/1535439/


All Articles