2008-10-07 9 views

Répondre

1

Vous pouvez créer un type qui enveloppe une action fournissant une mise en œuvre en tant que telle:

class ActionCommand 
{ 
    private readonly Action _action; 

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

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

Cela peut alors être utilisé comme ceci:

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