2008-10-07 91 views

回答

1

你可以創建一個包裝提供了一個實現這樣的動作類型:

class ActionCommand 
{ 
    private readonly Action _action; 

    public ActionCommand(Action action) 
    { 
     _action = action; 
    } 

    public override void Do() 
    { 
     _action(); 
    }     
}; 

這則可以使用像這樣:

Command c = new Command((Action)delegate() 
      { 
       // insert code here 
      });