Is it possible to pass a condition as parameter as you do with actions?
Here's an example.
public void Test(Action action, Condition condition);
...
Test( () => Environment.Exit(0), () => variable == varia开发者_Go百科ble2 );
Try passing the second argument as type Func<Boolean>
. The code should work as you have it in the second part of your question:
public void Text(Action action, Func<Boolean> condition) {
if (condition()) action();
}
EDIT: Note that what you would be doing in your usage example is creating a Closure containing the captured variables variable and variable2. You should understand the implications of closures before using them in this way.
精彩评论