如何知道事件的参数类型

vir*_*a24 3 c# events

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

例:

    // 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();
    }
Run Code Online (Sandbox Code Playgroud)

我怎么知道我的函数的参数是object sender和所有帧准备args?

Ser*_*rvy 6

您查找该事件的文档.它将指定委托定义该事件的内容.然后,您可以查找该委托的文档,以查看函数的签名必须与委托匹配.

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

请注意,参数的名称是无关紧要的(使用您想要的任何内容),只有类型很重要.