Difference betweeen event and delegate
2010-10-28 13:24
337 查看
Difference betweeen event and delegate is
1. Event : An event is a message sent by an object to signal the occurrence of an action. The action could be caused by user interaction, such as a mouse click, or it could be triggered by some other program logic. The object that raises (triggers) the event is called the event sender. The object that captures the event and responds to it is called the event receiver.
1). An event is not a type .
2). An event since its not a type can be declared in an interface.
3). An event is always invoked only on the object of the class where the event is defined/declared. So the method raised as part of the event should always be declared in the class that contains that object.
2. Delegate : A delegate is a class that can hold a reference to a method. Unlike other classes, a delegate class has a signature, and it can hold references only to methods that match its signature. A delegate is thus equivalent to a type-safe function pointer or a callback. While delegates have other uses, the discussion here focuses on the event handling functionality of delegates. The following example shows an event delegate declaration.
1). A Delegate is a type.
2). A Delegate since is a type cannot be declared in an interface.
3). As long as the reference of a method is attached to the delegate it can call that method regardless of its location.
1. Event : An event is a message sent by an object to signal the occurrence of an action. The action could be caused by user interaction, such as a mouse click, or it could be triggered by some other program logic. The object that raises (triggers) the event is called the event sender. The object that captures the event and responds to it is called the event receiver.
1). An event is not a type .
2). An event since its not a type can be declared in an interface.
3). An event is always invoked only on the object of the class where the event is defined/declared. So the method raised as part of the event should always be declared in the class that contains that object.
2. Delegate : A delegate is a class that can hold a reference to a method. Unlike other classes, a delegate class has a signature, and it can hold references only to methods that match its signature. A delegate is thus equivalent to a type-safe function pointer or a callback. While delegates have other uses, the discussion here focuses on the event handling functionality of delegates. The following example shows an event delegate declaration.
1). A Delegate is a type.
2). A Delegate since is a type cannot be declared in an interface.
3). As long as the reference of a method is attached to the delegate it can call that method regardless of its location.
相关文章推荐
- delegate and event
- delegate and event
- Difference between event.target and event.currentTarget properties in an event object.
- The Difference Between jQuery’s .bind(), .live(), and .delegate()
- C#编程利器之四:委托与事件(Delegate and event) (下)
- delegate and event
- Callback with event and delegate over .net remoting
- C#编程利器之四:委托与事件(Delegate and event)
- 委托和事件[delegate and event]_C#
- Good Example Telling Event and Delegate
- Observer Pattern, Delegate and Event
- 【唠叨两句】Event and delegate
- C# delegate and event
- delegate and event
- C#编程利器之四:委托与事件(Delegate and event) (上)
- Observer Pattern, Delegate and Event
- C#编程利器之四:委托与事件(Delegate and event) (下)
- Difference betweeen DECIMAL and NUMERIC
- The relation between event and delegate in visual c#
- event and delegate