Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call compositedelegate by position

Status
Not open for further replies.

jack1080

Programmer
Jun 2, 2007
34
MY
Consider following code:
delegate int MyDelegate();
MyDelegate d1=new MyDelegate(M1);
MyDelegate d2=new MyDelegate(M2);
MyDelegate d3=new MyDelegate(M3);
MyDelegate compDelegate=d1+d2+d3;

public void delegateCall(MyDelegate myCompDelegate, int Position){
//call the method by position
}

If I call delegate(compDelegate,2), meaning I want the second method to be called, in our case, d2.

How to do this?
 
use an array (or List<MyDelegate>())
Code:
MyDelegate[] compDelegate= new MyDelegate[]{ d1, d2, d3 };
public void delegateCall(MyDelegate myCompDelegate, int position)
{
   myCompDelegate[position];
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top