Friday, 26 October 2012

Delegate Part 2

In Delegate Part 1 :-I have explained how to declare a delegate and create an instance of it and use it. Now i am going to explain Multicast Delegate.

We can also create a delegate which can point to multiple functions and methods. If we invoke such delegate it will invoke all the methods and functions associated with the same one after another sequentially.In order to add multiple methods and function we need to use ‘+=’ symbols. Now if we invoke the delegate it will invoke ‘Method1’ first and then ‘Method2’. Invocation happen in the same sequence as the attachment is done.

// Associate method1
mydelegate += Method1;
// Associate Method2
mydelegate += Method2;
// Invoke the Method1 and Method2 sequentially

No comments: