Delegate is clear to understand
delegate int del(int i);
but why can we use
del myDelegate = x => x * x;
- How can I assure x is int type in the lambda expresison?
- How can I know lambda expression return a int?
C# compiler is smart enough to implicitly figure out the type of
As far as the return type goes, the compiler knows that
Note that the same code would not have compiled without the exact type of
Because for you to have x, you had to give it a type. It will detect this type rather than making you tell it over and over what type it is.
Actions return type is void while Func's return type is whatever you specify as the last type parameter. You can specify additional inputs in both
For returning an int