c# - Lambda 表达式而不是 Delegate
问题描述
我有Delegate
a
:
public delegate void doLog( String value , RichTextBox lger ) ;
public void doLg(String value, RichTextBox lger)
{
lger.AppendText(value);
}
doLog a = new doLog(doLg);
我在Invoke
通话中使用了这个委托:
_textBox.Invoke(a, new Object[] { "aaaa", _textBox });
如何使用 lambda 表达式让这一切变得更简单?
解决方案
我能想到的最简单的一种衬里就是这个
_textBox.Invoke(new Action(() => { doLog("aaaa", _textBox); }));
(它正在工作,因为 Action 只是委托)
推荐阅读
- c# - 我可以从 .net MVC 5 中的控制器修改动态属性值吗?
- reactjs - browserHistory.replace 将我带到路径“/”
- javascript - c# ReferenceError: 函数未定义
- node.js - 我的 npm 坏了 - 无法读取未定义的属性“get”
- android - UAMP MediaBrowser 方向
- node.js - Sequelize - 在验证模型的关联时获取正确的路径
- java - 无法播放整个音频片段
- python - 有人可以解释为什么用 python list 发生这种情况吗
- laravel - Homestead.yaml 文件中的授权和密钥选项有什么用?
- php - 通过数组键中的字符拆分数组