What does Action<Action> mean?
I just saw a brand-new video on the Rx framework, and one particular signature caught my eye:
Scheduler.schedule(this IScheduler, Action<Action>)
At 23:55, Bart de Smet says:
The earliest version wou开发者_如何学Pythonld be Action of Action.
If Action
is a parameterized type, how can it appear unparameterized inside the angle brackets again? Wouldn't it have to be Action<Action<Action<...>>>
ad infinitum, which is obviously impossible?
Action<T>
describes a delegate that takes a single parameter of type T. Action
describes a delegate that takes no parameters.
See http://msdn.microsoft.com/en-us/library/system.action.aspx
Action
has several overloads. One is non-generic, the others take one, two, three, etc. type parameters. Suppose they had different names, the one-argument version being called Action1
, and the zero-argument (non-generic) being called Action0
, then the example would be Action1<Action0>
.
From MSDN:
- Action
- Action<T>
Action example
Action showMethod = () => { Console.WriteLine("Line"); };
showMethod();
Action<T> example
Action<int> showMethod = (i) => { Console.WriteLine("Line {0}", i); };
showMethod(1);
Action has a non-generic version with the signature:
public delegate void Action();
So it is an Action that takes an Action of type void. Looks funny, but is perfectly valid.
Default parameter seems like the easy solution here.
精彩评论