gpt4 book ai didi

c# - 如何知道事件有什么样的参数

转载 作者:行者123 更新时间:2023-11-30 13:26:48 25 4
gpt4 key购买 nike

我有一个事件,我将我的处理程序与它相关联。当我编写我的处理程序方法时,我如何知道该函数采用哪些参数?

例子:

    // Add an event handler to be called whenever there is new color frame data
this.sensor.ColorFrameReady += this.SensorColorFrameReady;
this.sensor.AllFramesReady += this.AllFramesReady;

//handler
private void AllFramesReady(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs)
{


throw new NotImplementedException();
}

我怎么知道我的函数的参数是object sender 和所有帧就绪参数?

最佳答案

您查找该事件的文档。它将指定什么委托(delegate)定义了该事件。然后,您可以查找该委托(delegate)的文档,了解函数的签名必须是什么才能匹配该委托(delegate)。

或者您可以依靠 Visual Studio 告诉您而不是查找它,这是大多数人所做的。 (将鼠标悬停在事件上会告诉您委托(delegate)必须是什么,或者在键盘中键入 SomeEvent += 会提示您选择创建具有正确签名的事件处理程序的新 stub 。)

请注意,参数的名称是无关紧要的(使用任何你想要的),只有类型才是重要的。

关于c# - 如何知道事件有什么样的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17457721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com