Conditional Delegate Question
Let's say I open a form and want to attach a command to it after it closes.
FormZombie FormZombie = new FormZombie();
FormZombie.Show();
FormZombie.FormClose += delegate{Utili开发者_开发技巧ties.DoSomethingCool()};
How can I make Utilities.DoSomethingCool() trigger only executes depending on what happens in FormZombie?
You can add the conditional check into your delegate:
FormZombie formZombie = new FormZombie();
formZombie.Show();
formZombie.FormClose +=
delegate
{
if (formZombie.AteEnoughBrains)
Utilities.DoSomethingCool();
};
精彩评论