From what I am reading, a delegate instance is always defined with a class as an input or inside a class.
Why can't I define a delegate instance independently?
From what I am reading, a delegate instance is always defined with a class as an input or inside a class.
Why can't I define a delegate instance independently?
A delegate is a type, and you can define it at namespace scope (including the global namespace).
Since delegates are reference types, delegate instances always are placed on the managed (garbage collected) heap. Delegate instances can be created with the
gcnew
operator, theDelegate::CreateDelegate
method, or using stack semantics syntax (C++/CLI only).A reference variable of delegate type (including stack semantics syntax variables which wrap a permanently-bound reference, an instance on the heap, and an automatic call to
IDisposable::Dispose
) can exist as an instance or static member of a managed type, an automatic local variable, a static local variable, or (in C++/CLI) as a global (namespace scope) variable.