Pages

Showing posts with label Delegates and Events. Show all posts
Showing posts with label Delegates and Events. Show all posts
Tuesday, January 17, 2012

Events and Delegates

0 comments
Events and delegates work hand-in-hand to provide a program's functionality.

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.

A delegate is a class that can hold a reference to a method that matches its signature. A delegate is thus equivalent to a type-safe function pointer or a callback.

Events are defined with the help of delegates.
Continue reading →
Sunday, January 15, 2012

Delegates

0 comments

Delegates 

A delegate is a type that references a method means it holds the address of method. It allows encapsulating a reference to a method inside a delegate object. A delegate can be assigned a method after which it can be used like any other method. You must define the delegate to match the signature of the method it will point to.

Delegates Overview



·  Delegates are similar to C++ function pointers, but are type safe, object-oriented and  secure.
·  Delegates hold the address of one function or addresses of many functions.
·  Delegates encapsulate some information like class names and methods names.
·  If a Delegate is holding the address of only one function then it is called as single cast Delegate.
·  If a Delegate is holding the addresses of many functions then it is called as Multicast Delegate.
·  C# version 2.0 introduces the concept of Anonymous Methods, which permit code blocks to be passed as parameters in place of a separately defined method.
·  Delegates can be used to invoke methods Asynchronously.
Continue reading →

Labels