C# Action

A delegate in C# represents a reference type that encapsulates a method. When we declare a delegate type we specify some parameters and a return type. We can only store those methods in delegates which has same parameters and same return type. Microsoft introduced some pre-built delegates so that we don't have to declare delegates every time. Action is one of the pre-built delegates.

Action in C# represents a delegate that has void return type and optional parameters. There are two variants of Action delegate.

Action

Action<in T>

Non-Generic Action Delegate

First variant is non-generic delegate that takes no parameters and has void return type. In this Action delegate, we can store only those methods which has no parameters and void return type.

We have to choose Action delegate according to the method, which we want to store. If our method takes two parameters, then we have to choose action delegate which has two parameters Action<in T1, T2>(T1 arg1, T2 arg2). Below are some examples