Hi
@aashima is explained a better way ,So thanks
I put some more light here on Delegate in C#.
1 - It is as like as the function pointers in c++
2- Func delegate is a pointer to method that takes one or more parameters and must return a value
3- Func<> is a kind of Multicast Delegate used frequently with LINQ
static Func<int, int, float, double> add = delegate (int x, int y, float c) { return x + y + c; };
Console.WriteLine(add(2, 3, 5.5f)); // Outputs "10.5"
In lambda
Func<int, int, float, double> add = (a, b, c) => a + b + c;
//In case of function can take argument type any .Here can not take float then long
int[] ints = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
One of the overloaded versions of the LINQ Where operator accepts a Func delegate:
IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<int, bool> predicate);
So we declare our Func:
Func<int, bool> GreaterThanTwo = i => i > 3;
Then we declare our query:
IEnumerable<int> intsGreaterThanTwo = ints.Where(GreaterThanTwo);
Thanks and regards