Yes, there are different overloads of Action
taking a different number of input parameters and having a void
return type.
Action public delegate void Action()
Action<T> public delegate void Action<T>(T obj)
Action<T1,T2> public delegate void Action<T1,T2>(T1 arg1, T2 arg2)
Action<T1,T2,T3> public delegate void Action<T1,T2,T3>(T1 arg1, T2 arg2, T3 arg3)
...
The first line is what you are looking for.
Newer Framework versions have added overloads with even more arguments.
Maximum number of arguments:
- .NET Framework 2.0: 1
- .NET Framework 3.5: 4
- .NET Framework 4.0: 16
- Silverlight: 16
Actions have always a void
return type. A void
return type need not and cannot be specified as generic type parameter. By contrast, the Func
delegates define "real" return types and have always at least one generic type parameter for the return type. Refer here
Func<TResult> public delegate TResult Func<TResult>()
Func<T,TResult> public delegate TResult Func<T,TResult>(T arg)
Func<T1,T2,TResult> public delegate TResult Func<T1,T2,TResult>(T1 arg1, T2 arg2)
...
.NET Framework 4.0 has added in
and out
modifiers to the generic type parameters for contravariance and covariance. See: Covariance and Contravariance in Generics. Examples:
public delegate void Action<in T1, in T2>(T1 arg1, T2 arg2)
public delegate TResult Func<in T1, in T2, out TResult>(T1 arg1, T2 arg2)