Understanding C# Events use of sender object

后端 未结 5 1068
时光说笑
时光说笑 2020-12-09 14:07

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.

5条回答
  •  青春惊慌失措
    2020-12-09 14:50

    In .NET, all classes are reference types, and a reference is always passed... by reference (the current implementation of a reference is a pointer that can be moved around by the GC when it needs to), so you don't have to worry about anything.

    About events, the sender parameter is always the object that generated the event (for example a Button in a Click event on a button). If you want to pass arbitrary data in a custom event, inherits from EventArgs and pass it as the second argument.

提交回复
热议问题