Return type Delegate and Func.

Suleiman Abdullah
3 min readOct 8, 2024

--

Objective: Return type Delegate and Func.

Return type delegate is the type of delegate which return data type, I will define a delegate signature and create a variable.

Note: If you are new to C# delegate please go check my article about delegate.

Make sure the function follow the signature, I have create a return method which return int, the return variable is global variable I create to add some fake logic.

We call it as we call normal delegate, nothing change.

What is a Func?

This is a built-in return type delegate, which can take parameter and return type for method signature in T bracket.

To create a func delegate we use keyword func after access modifier, followed by T bracket and name of delegate.

Inside the T bracket a first parameter is will be a return type if its only one.

But If you want func delegate to take a parameter and return other data type.

A first parameter in T bracket will be a parameter(T) separate by comma and second parameter will be a result(Tresult) aka a return data type of method signature.

Note: We are not limited to only two parameter, we can add more than two parameter just check the tool tip for more option on how many parameter you can add.

This func delegate don't need extra variable, we call it using the same delegate variable.

Those number i put in func delegate is a parameter, plus Ignore the number i add on return method I put it just to get rid of error. I assume at this level you are not beginner any more about return method.

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