| Difference between Func Action and Predicate
Below are the important aspects and difference in this above 3 generic delegates:-
(1)Func
Func is a generic delegate included in the System namespace
(i)Func type is built-in delegate.
(ii)Func delegate type must return a value.
(iii)Func delegate type have 0 to 16 input parameters.
(iv)Func delegates not allow ref and out parametrs.
(v)We can use Func delegate types with anonymous method or with lambda expression.
(2)Action
Action is also a delegate type defined in the System namespace.
(i)Action delegate is same as Func delegate except it does not return anything.
(ii)Return type must be void
(iii)Action delegate can take 0 to 16 input parameters.
(iv)We can use Action delegate types with anonymous method or with lambda expression.
(3)Predicate
The Predicate delegate is defined in the System namespace.
(i)Predicate is generic inbuilt delegates.
(ii)A predicate delegate methods will take one input parameter and return a boolean.
(iii)Anonymous method and Lambda expression can be assigned to the predicate delegate
(iv)It is mainly used with collections to check whether itme in collection is correct or not. | | |