简体   繁体   English

C#中的回调/事件

[英]Callbacks / Events in C#

Iv'e pretty new to C# ATM and I seem to be having trouble with Jabber-Net 我对C#ATM相当陌生,而且似乎在Jabber-Net上遇到了麻烦

Im trying to create a basic chat application that will connect users via Jaber Services, the issues im having are with the Callbacks. 我试图创建一个基本的聊天应用程序,该应用程序将通过Jaber Services连接用户,而我遇到的问题是回调。

The main error I seem to get is about the "Event required but used like 'type'", or something along those lines.. 我似乎遇到的主要错误是关于“必需的事件,但像'类型'这样使用”,或类似的东西。

Im at work atm so i cant give you full details but it seems to be when i try adding callbacks.. For example: 我在工作atm,所以我无法向您提供完整的详细信息,但似乎是当我尝试添加回调时。.例如:

JabberClient Jabber = new JabberCLient();
Jabbaer.OnConnect += new jabber.connection.XmppStream.OnConnect(Some_event_function);

Now this code was just of the top of my head and may be wrong, i work by fixing errors as I'm learning but I get an error that basically telling me that what im doing should be done as an event but im using as a type 现在这段代码只是我的头上的,可能是错误的,我在学习时通过修复错误来工作,但是我得到一个错误,该错误基本上告诉我即时消息应该作为事件来完成,而即时消息应用作类型

Can anybody shed some light on the matter please. 任何人都可以对这个问题有所了解。

Regards Robert Pitt 问候罗伯特·皮特

将第二行替换为:

Jabber.OnConnect += Some_event_function;

In principle, the line 原则上,线

  Jabbaer.OnConnect += new 
      jabber.connection.XmppStream.OnConnect(Some_event_function);

is wrong because XmppStream.OnConnect is a property and you need a delegate definition at that point. 是错误的,因为XmppStream.OnConnect是一个属性,此时您需要一个委托定义。 But instead of debugging what came from your memory, just use the shorthand form: 但是,您无需调试内存中的内容,而只需使用简写形式:

  Jabbaer.OnConnect += Some_event_function;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM