Events and delegates
Delegate and Event concepts are completely tied together. Even if they were exactly the same thing there will still remain the semantical difference. Delegates is a function pointer which can able to store the address of any function with same prototype. While Event is a function handler which can handles or run the functions in same prototype of its delegate.
A delegate is a more generic term to describe a construct similar to a pointer in C/C++ terms. It holds a reference to a method and to an object instance (if the method is non-static). All delegates in .Net are multicast delegates i.e. they hold references to several object/method pairs. Conceptually we can considered it as function templates; that is, they express a contract a function must adhere to in order to be considered of the "type" of the delegate.
An event is just a wrapper for a multicast delegate. An Event declaration adds a layer of abstraction and protection on the delegate instance. Adding a public event to a class is almost the same as adding a public multicast delegate field. In both cases, subscriber objects can register for notifications, and in both cases the publisher object can send notifications to the subscribers.
What is .Net Delegates
In the .NET environment, a delegate is a type that defines a method signature and it can pass a function as a parameter. In simple words we can say delegate is a .NET object which points to a method that matches its specific signature. More details about... .Net Delegates
- Does C# support multiple Inheritance ?
- What is Process ID ?
- How do I make a DLL in C# ?
- How many ways you can pass values to Windows Services ?
- Can we use "continue" statement in finally block ?
- What is nullable type in c# ?
- Difference between the Debug class and Trace class ?
- What is lock statement in C#
- What are dynamic type variables in C#
- What is the difference between is and as operator in C#?
- What are circular references in C#?
- Explain the types of unit test cases in C#?
- How many types of comments are there in C#?
- What are the various ways to pass parameters to a method in C#?
- What are the different ways to deploy a assembly in net?
- What does assert() method do in c#
- What is literals in C# - Constants and Literals
- What is the use of goto statement in C#
- How can JIT code be faster than AOT compiled code
- Why events have no return types in .NET
- What's the difference between a static method and a non-static method in C#
- What's a weak reference c#?
- What is C# equivalent of the vb.net isNothing function
- What are indexers in C#
- What are generics in c#