c# - How does anonymous methods omit parameter list? -
i reading in msdn documentation on anonymous methods (c# programming guide), not understand part omitting parameter list. says:
there 1 case in anonymous method provides functionality not found in lambda expressions. anonymous methods enable omit parameter list. means anonymous method can converted delegates variety of signatures. not possible lambda expressions.
my understanding special case when anonymous methods not using arguments. anonymous methods can leave out parameters entirely. correct?
i think confused lambda expressions , anonymous methods. need understand lambda expressions syntantic sugars.for example, can create anonymous method takes 2 integer parameter , returns integer
this:
func<int, int, int> func = delegate(int x, int y) { return x + y; };
using lambda syntax can shorten statement this:
func<int, int, int> func2 = (x,y) => return x + y;
also don't need pass argument lambda statement.for example valid:
action act = () => console.writeline("hello world");
so result, lambda expressions allows create anonymous methods less code , don't have disadvantages compared anonymous methods because different things.you comparing apples oranges.
Comments
Post a Comment