了解 C# 事件对发送者对象的使用 [英] Understanding C# Events use of sender object

查看:20
本文介绍了了解 C# 事件对发送者对象的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 C# 作为一种语言相当陌生(来自 C++ 背景),我目前正在编写一个使用事件驱动 API 的应用程序.

I am reasonably new to C# as a language (coming from a C++ background) and I am currently in the process of writing an application that makes use of an event driven API.

这主要包括注册事件/响应处理程序和启动事件监视器,然后处理这些异步事件/响应.

Primarily this consists of registering event/response handlers and starting event monitors then dealing with these asychronous events/responses.

我在理解发件人对象时遇到了一些麻烦.

The thing i'm having a bit of trouble understanding is the use of the sender object.

我想使用它的目的是在发出请求(或设置监视器)时将句柄传递给我具有各种结构和数据的类对象.然后在收到响应/引发事件时,我可以获取发送者对象,将其转换回预期的类类型和访问成员,进行进一步的更改等,因此将其视为仍然是指向原始数据的指针(我希望它是?).

What I would like to use it for is to pass a handle to a class object I have with various structures and data in when making a request (or setting up a monitor). And then on the response being recieved/the event being raised I can take the sender object, cast it back to the expected class type and access members, make further changes etc. so treating it as if it's just still a pointer to the original data (which I'm hoping it would be?).

所以我的问题真的是,当我在我的请求中传递一个类对象时,这是否是一个有效的引用,或者它是否会按值复制到某个地方,因为它实际上只是一个通用对象,我将结束是否在事件中提供我的类对象的空副本?

So my question really is, as I am passing a class object in my request, will this be effectively a reference, or will it be copied somewhere along the line by value as it is actually just a generic object and I will end up with an empty copy of my class object on the event?

或者第三个选项,我可能在这里完全走错了路,应该忘记整件事?:)

Or the third option that i'm maybe completely on the wrong track here and should forget the whole thing? :)

问题是我的大脑仍然在我认为的指针模式下工作......

Problem is my brains still working in pointers mode I think...

推荐答案

我不知道我完全理解你的问题.但要部分回答您:

I don't know that I entirely understand your question. But to answer you in part:

您将获得对您的对象的引用.

You would get a reference to your object.

这篇关于了解 C# 事件对发送者对象的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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