将条件作为参数传递
是否可以像操作操作一样将条件作为参数传递?
这是一个例子。
public void Test(Action action, Condition condition);
...
Test( () => Environment.Exit(0), () => variable == variable2 );
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 == variable2 );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将第二个参数作为
Func
类型传递。该代码应该像您在问题的第二部分中一样工作:编辑:请注意,您在使用示例中要做的是创建一个 包含捕获的变量variable和variable2的闭包。在以这种方式使用闭包之前,您应该了解闭包的含义。
Try passing the second argument as type
Func<Boolean>
. The code should work as you have it in the second part of your question: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.