DEV Community

Cover image for Actions, Predicate, and Func
Shreyans Padmani
Shreyans Padmani

Posted on

Actions, Predicate, and Func

In C#, Action, Predicate, and Func are powerful delegates that help us write flexible and reusable code. Let’s break down what they do and when to use them.

Action

  • Represents a method that returns void.
  • Can take 0 to 16 input parameters.
  • Commonly used for operations that don't return a value.

Image description

Predicate

  • Represents a method that returns a boolean (bool).
  • Takes exactly one input parameter of type T.
  • Ideal for conditions and filtering.

Image description

Func

  • Represents a method that returns a value.
  • Can take 0 to 16 input parameters.
  • The last type parameter defines the return type.

Image description

Conclusion

  • Understanding Action, Predicate, and Func helps you:
  • Write more concise and expressive code.
  • Avoid unnecessary custom delegates.
  • Work easily with LINQ, events, and functional programming patterns.
  • Use them wisely to make your C# code cleaner, modular, and reusable

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.