July 31, 2021

System Defined Delegates

Action - When you want a delegate for a member/method that may or may not take parameters (up to 16 parameters max, none as the minimum) and does not return anything. The pattern is Action<T1, ..., T16>, so a member/method with 0 to 16 parameters that has no return value.

Func - When you want a delegate for a member/method that may or may not take parameters (up to 16 parameters max, none as the minimum) but that always returns a result. The pattern is Func<T1, ..., T16, TResult>, so a method with 0 to 16 parameters that returns a TResult.

Predicate - Defined as public delegate bool Predicate<in T>(T myObject);. A special delegate used by several methods of the Array and List<T> classes to search for elements in the collection. In other cases use a Func<T, bool>

No comments: