What is Action in C#

Suleiman Abdullah
2 min readOct 8, 2024

--

Objective: Understand What is Action in C#.

Action is the type of delegate which accept only method with no return type, and give us T bracket to allow us to pass type parameter of the method.

To create action delegate we use keyword action, and give a name .

This type of delegate does not need to create a variable for method signature like event and normal delegate. We use this name direct without create addition variable.

We also use the same variable to subscribe to this event outside this class. To access it easily I will set this action to static.

Note: To use plus equal sign to subscribe is not mandatory like an event, we use equal sign to register our method to the action delegate.

Inside normal Enemy script

If you want to allow method to pass parameter we add T bracket and inside we specify a data type after keyword Action. But by doing this a method mass pass that data type to be satisfied.

But make Sure your method has the same signature or fix your method to take same parameter type.

Why should you use this over delegate type?

This is more simplified, only single statement to define delegate.

Use this when your method need to make sure they don't return anything .

See you into the next one.

--

--

Suleiman Abdullah

Self taught Unity Developer, who is passion about making games ,and he loves Math For Game Development