首页 > 解决方案 > 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 表达式让这一切变得更简单?

标签: c#lambdadelegates

解决方案


我能想到的最简单的一种衬里就是这个

_textBox.Invoke(new Action(() => { doLog("aaaa", _textBox); }));

(它正在工作,因为 Action 只是委托)


推荐阅读