Jan*_*oom 36
您可以定义Action
对象,这些对象是返回的无参数委托void
.每个动作都是指向方法的指针.
// Declare the list
List<Action> actions = new List<Action>();
// Add two delegates to the list that point to 'SomeMethod' and 'SomeMethod2'
actions.Add( ()=> SomeClass.SomeMethod(param1) );
actions.Add( ()=> OtherClass.SomeMethod2() );
// Later on, you can walk through these pointers
foreach(var action in actions)
// And execute the method
action.Invoke();
Run Code Online (Sandbox Code Playgroud)
怎么样Queue<Action>
?
var queue = new Queue<Action>();
queue.Enqueue(() => foo());
queue.Enqueue(() => bar());
while(queue.Count != 0)
{
Action action = queue.Dequeue();
action();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
23278 次 |
最近记录: |