As I know every delegate inherits System.Delegate. A multicast delegate inherits System.MulticastDelegate. When I declare a delegate it automatically inherits System.Delegate but if i use Delegate.Combile / Delegate.Remove (or +=, -= respectively) this means that the delegate is a multicast delegate and it should inherit MulticastDelegate. Does this mean that the compiler creates from the inheritor of System.Delegate a new object delegate that inherits System.MulticastDelegate? And when does this happen, when I use +=/-= or in some other time?
when you create a delegate, you don't inherit from delegate, you declare it a delegate just like you declare a class or struct.
Well, not explicitly (and you're not allowed to do so anyway). However, delegates are implicitly Delegate-derived, as classes are implicitly Object-derived, and structs implicitly inherit ValueType, and enumerations implicitly derive from the Enum class, etc.
As to the OP's question: MulticastDelegate derives from Delegate itself, which means a MulticastDelegate is (a specialized kind of) Delegate, at the same time. I think that the C# compiler derives a user defined delegate from MulticastDelegate, and that the Delegate class probably only defines common functionality, and is otherwise used by the system.
To quote MSDN docs: "[...] only the system and compilers can derive explicitly from the Delegate class or from the MulticastDelegate class. It is also not permissible to derive a new type from a delegate type. The Delegate class is not considered a delegate type; it is a class used to derive delegate types.
Most languages implement a delegate keyword, and compilers for those languages are able to derive from the MulticastDelegate class; therefore, users should use the delegate keyword provided by the language."
So, these are basically internal details you don't have to worry about. Just use += and -=.
Bookmarks