C# Interview Question #55

What are Action, Func, and Predicate delegates?

Exceptions, Delegates, Events & Lambdas Mid-Level Intermediate

Quick Interview Answer

Action, Func, and Predicate are built-in generic delegate types.

Detailed Explanation

Action, Func, and Predicate are built-in generic delegate types.

Action represents a method that returns void and can accept parameters. Func represents a method that returns a value; its final generic type parameter is the return type. Predicate<T> represents a method that accepts T and returns bool.

These built-in delegates reduce the need to declare custom delegate types for common scenarios.

Code Example

Action<string> print = message =>
    Console.WriteLine(message);

Func<int, int, int> add = (a, b) => a + b;

Predicate<int> isAdultAge = age => age >= 18;