如何在 C# 中对 Dictionary> 使用 Delegate
代码:
[1]
private delegate void ThreadStatusCallback(ReceiveMessageAction action,
Dictionary<int, List<string>> message);
[2]
Dictionary<int, List<string>> messagesForNotification =
new Dictionary<int, List<string>>();
[3]
Invoke(new ThreadStatusCallback(ReceivesMessagesStatus),
ReceiveMessageAction.Notification , messagesForNotification );
[4]
private void ReceivesMessagesStatus(ReceiveMessageAction action, object value)
{
...
}
如何分别发送ReceiveMessageAction
类型的两个变量Dictionary
到 ReceivesMessagesStatus 方法。
谢谢。
我有一个在线程中执行的函数。在这里,我创建了一个 Dictionary
类型的对象,并使用委托,我想在我的表单中使用该对象。
部分代码如上: [1] 受托人宣誓 [2] 对象 [3] 代表的召唤 [3] 需要发送对象的函数
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过使用 lambda 来实现类型安全,而无需进行强制转换:
You can do it type-safe without casting by using a lambda:
您是否尝试过将 value 转换为字典?例如
Have you tried casting value as a Dictionary? e.g.
解决方案:
[1]
[2]
Solution:
[1]
[2]