When I'm trying to use params in an Action delegate...
private Action<string, params object[]> WriteToLogCallBack;
I received this design time error:
Invalid token 'params' in class, struct, or interface member declaration
Any help!
When I'm trying to use params in an Action delegate...
private Action<string, params object[]> WriteToLogCallBack;
I received this design time error:
Invalid token 'params' in class, struct, or interface member declaration
Any help!
Variadic type parameters are not possible in C#.
That's why there're many declarations for
Action<...>
,Func<...>
, andTuple<...>
, for example. It would be an interesting feature, though. C++0x has them.I have done a minor extension to the above code from Bryan, to show how to wrap multiple method calls.
I am using this to wrap multiple methods that contain database calls, into a single transaction.
Thanks Bryan :-)
(You can run the following in LINQPad to test)
You can use
params
in the actual declaration of a delegate, but not in type of one. The generic parameters to an Action are only types, not the actual arguments to be passed when invoking the delegate. params is not a type, it is a keyword.You could try this. It allows for any number of arguments, and you'll get a compile time error if you pass the wrong number or type of arguments.
How about this workaround?
Or you could define your own delegate type: