错误10委派'System.Action' [英] Error 10 Delegate 'System.Action'

查看:49
本文介绍了错误10委派'System.Action'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些代码在这里

some code here

Action<string> messagetarget;
messagetarget = delegate(string s) { showmessage(s); };
//this.Invoke(messagetarget);



还有一些代码



and some code here

public void showmessage(string thid1)
{
    lvc[0] = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
    lvc[1] = thid1;
    listView2.Items.Add(new ListViewItem(lvc, 0));
}



如果编写此代码,则会出现错误



and if a write this code a got an error

    Action<string> messagetarget;
    messagetarget = delegate(string s, string t) { showmessage(s, t); };
    this.Invoke(messagetarget);

public void showmessage(string thid1,string message1)
{
    lvc[0] = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
    lvc[1] = thid1;
    lvc[2] = message1;
    listView2.Items.Add(new ListViewItem(lvc, 0));
}



我收到一个错误:

Error 10 Delegate ''System.Action<string>'' does not take 2 arguments C:\Users\bibo\Desktop\KryptonFormProject1\KryptonFormProject1\Form1.cs 223 29 KryptonFormProject1

您能解释一下我该怎么办吗?



i got an error:

Error 10 Delegate ''System.Action<string>'' does not take 2 arguments C:\Users\bibo\Desktop\KryptonFormProject1\KryptonFormProject1\Form1.cs 223 29 KryptonFormProject1

can you explain me what can i do ??

推荐答案

看看您对messagetarget的声明-只有一个参数,而您正在尝试传递给委托人两个参数.
Look at your declaration for messagetarget - there''s only one parameter, and you''re trying to pass the delegate two parameters.


更改
Action<string> messagetarget

Action<string,string> messagetarget



请参见 Action< T1,T2>委托 [ ^ ]



See Action<T1, T2> Delegate[^]


这篇关于错误10委派'System.Action'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆