C#中的事件数组?

编程入门 行业动态 更新时间:2024-10-28 13:17:41
本文介绍了C#中的事件数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

基本上:

public delegate void RecvCommandHandler (ChatApplication sender, byte[] content); event RecvCommandHandler[] commands = new RecvCommandHandler[255];

我想为每个命令编号激活一个不同的方法/函数,但我真的不确定句法。我应该怎么做?

I want to activate a different method/function for each command number, but I am really uncertain of the syntax. How am I supposed to do it?

我想我会和这个代表团一起去,但问题仍然很有意思。

I think I'll go with just an array of delegates for this one, but the question is still interesting.

推荐答案

真的没有一个事件数组的概念 - 就像谈论一个属性数组。事件真的只是让您订阅并取消订阅处理程序的方法。如果你需要通过索引来做到这一点,我建议你只需要一个方法。 ( AddCommandHandler(int,RecvCommandHandler)和 RemoveCommandHandler(int,RecvCommandHandler))。这不支持正常的事件处理语法糖,当然,但我看不到有很多替代方案。

There's really no concept of an array of events - it's like talking about an array of properties. Events are really just methods which let you subscribe and unsubscribe handlers. If you need to be able to do this by index, I suggest you just have a pair of methods. (AddCommandHandler(int, RecvCommandHandler) and RemoveCommandHandler(int, RecvCommandHandler)). That won't support the normal event handling syntactic sugar, of course, but I don't see that there's a lot of alternative.

更多推荐

C#中的事件数组?

本文发布于:2023-10-16 06:58:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!