C#如何使用多个参数调用

Iva*_*nov 11 c# invoke winforms

我使用下面的代码访问我的表单上的属性,但今天我想把东西写入ListView,这需要更多的参数.

    public string TextValue
    {
        set
        {
            if (this.Memo.InvokeRequired)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    this.Memo.Text += value + "\n";
                });
            }
            else
            {
                this.Memo.Text += value + "\n";
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

如何添加多个参数以及如何使用它们(值,值)?

Mar*_*ell 29

(编辑 - 我想我误解了原来的问题)

只需将其设为方法而不是属性:

public void DoSomething(string foo, int bar)
{
    if (this.InvokeRequired) {
        this.Invoke((MethodInvoker)delegate {
            DoSomething(foo,bar);
        });
        return;
    }
    // do something with foo and bar
    this.Text = foo;
    Console.WriteLine(bar);
}
Run Code Online (Sandbox Code Playgroud)