Introduction In this article, we are going to discuss Action and Func delegates in C# and how we use them. As we already know, a Delegate in C# is a type-safe method pointer and we are using it to handle the callback or an event. Actions and Funcs are just delegates but are pre-defined in System Namespace so that we don’t need to define the custom delegates manually. Syntax Both Action and Func delegates can have multiple input parameters. A Func delegate returns a value while an Action does not, this is the only difference between them. C# provides 17 overloads of Action delegate in the System Namespace, one of them is: public delegate void Action<in T>(T obj); This Action delegate would only accept one argument of type T. However, it can support up to 16 arguments of type T. Similarly, there are total of 17 overloads of Func delegate defined in the System Namespace, one of them is: public delegate TResult Func<out TResult...
Discover the art of Programming, Architecture and Software Development Best Practices through my well-crafted Blog articles. Stay up-to-date with the latest trends and technologies and with tips & tricks to enhance your skill