You can create a delegate type declaration:
delegate int del(int number);
and then assign and use it:
del square = delegate(int x)
{
return x * x;
};
int result= square (5);
Or, as said, you can use the "shortcut" for delegates (it is made by delegates) and use:
Func<[inputType], [outputType]> [methodName]= [inputValue]=>[returnValue]
eg:
Func<int, int> square = x=>x*x;
int result=square(5);
You also have two other shortcuts:
Func with no parameters: Func<int> p=()=>8;
Func with two parameters:Func<int,int,int> p=(a,b)=>a+b;
source
share