When I inherit Delegate or MulticastDelegate classes I am getting compiler error, both are normal abstract classes only even though why I am unable to inherit these classes.
Could you please tell me any one why these classes are not considered as base class?
Because it is very, very important that objects of a derived class of MulticastDelegate are immutable. Which ensures that state cannot get corrupted when arbitrary code you don't know about subscribes an event handler. Immutability in .NET is implemented by convention, you make fields private, don't provide property setters, don't provide a default constructor.
This is not a trait that can be inherited, you could derive a class for an immutable base class and make it mutable. And violate the immutability requirement.
So the compiler has a hard-baked rule about it and rejects your attempt at deriving from MulticastDelegate yourself. It reserves the right, insisting it can only do it properly itself, you have to use the delegate keyword. And does more, it automatically creates proper declarations for the Invoke() and BeginInvoke() methods, declarations that force you to use these methods in a type-safe way.
This will not slow you down.
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