What's the code syntax for declaring a subclass of EventHandler (that you've defined) in an interface?
I create the EventHandler subclass MyEventHandler for example in the delegate declaration, but you can't declare a delegate in an interface...
When I ask Visual Studio to extract an interface it refers to the EventHandler in IMyClassName as MyClassName.MyEventHandler which obviously plays havoc with type coupling.
I'm assuming there is a simple way to do this. Do I have to explicitly declare my event handler in a separate file?
The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .
C operators are one of the features in C which has symbols that can be used to perform mathematical, relational, bitwise, conditional, or logical manipulations. The C programming language has a lot of built-in operators to perform various tasks as per the need of the program.
In C/C++, the # sign marks preprocessor directives. If you're not familiar with the preprocessor, it works as part of the compilation process, handling includes, macros, and more.
Well, you need to define the args and possibly delegate somewhere. You don't need a second file, but I'd probably recommend it... but the classes should probably not be nested, if that was the original problem.
The recommendation is to use the standard "sender, args" pattern; there are two cmmon approaches:
1: declare an event-args class separately, and use EventHandler<T>
on the interface:
public class MySpecialEventArgs : EventArgs {...} ... EventHandler<MySpecialEventArgs> MyEvent;
2: declare an event-args class and delegate type separately:
public class MySpecialEventArgs : EventArgs {...} public delegate void MySpecialEventHandler(object sender, MySpecialEventArgs args); .... event MySpecialEventHandler MyEvent;
Assuming C# 2.0 or later...
public class MyEventArgs: EventArgs { // ... your event args properties and methods here... } public interface IMyInterface { event EventHandler<MyEventArgs> MyEvent; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With