Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi all

Can anyone please answer this question.

Thank you
Posted
Updated 30-May-16 2:47am
Comments
Richard MacCutchan 19-Feb-15 12:32pm    
Sorry but that makes no sense. Please edit your question show the code and explain what it is supposed to do.
Black_Rose 19-Feb-15 12:34pm    
No actually this was asked in one interview i faced.
Richard MacCutchan 19-Feb-15 12:40pm    
Still makes no sense, methods are not "consumed".
Black_Rose 19-Feb-15 12:48pm    
Then is there any other way to relate this question.
Black_Rose 19-Feb-15 12:53pm    
Ok.may be this will help. please tell me
i have 2 classes in my project, which contains one method each.
how to call both of the methods in a single event.

"please tell me
i have 2 classes in my project, which contains one method each.
how to call both of the methods in a single event.
...
instance methods."


Instance methods require instances of their respective classes - so in order to call two instance methods from different classes in the same event handler, you need to find a way to get the instances into the method.

If the instances are contained within a class (such as a form) and stored as variables, then that's easy:
C#
public class MyForm : Form
   {
   private MyClass1 mc1 = new MyClass1();
   private MyClass2 mc2 = new MyClass2();
   ...
   void MyForm_Event(object sender, EventArgs e)
      {
      mc1.MyMethod1();
      mc2.MyMethod2();
      }
   }
If they aren't, then it gets more complex as you have to find a way to pass the instances through (or create them in the event handler, but that means you get new instances, and it won't affect any instances outside the method)
 
Share this answer
 
I think the solution is Multicast Delegates :

A useful property of delegate objects is that multiple objects can be assigned to one delegate instance by using the + operator. The multicast delegate contains a list of the assigned delegates. When the multicast delegate is called, it invokes the delegates in the list, in order. Only delegates of the same type can be combined.

Please check the following :


https://msdn.microsoft.com/en-us/library/ms173175.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900