In my main class ‘A’ I have declared a function and delegate to call that function, I want to pass my delegate to another class ‘B’ but how will class B know what type the delegate is?
class A
public delegate void SendInfo(string[] info);
SendInfo sendInfo = new SendInfo(SendInformation); //I have a function SendInformation
B b = new B();
b.SetDelegate(sendInfo);
class B
public delegate void SendInfo(string[] info); //I know this is wrong but how will
SendInfo SendInformation; //this class know what SendInfo is?
public void SetDelegate(SendInfo sendinfo) //What type is this parameter?
{
sendinfo.GetType();
SendInformation = sendinfo;
}
Thanks,
Eamonn
When you declare the delegate ‘in’ class A, you declare it as a sub-type of class A. So it’s of type
ClassA.SendInfofor example. In class B you could useAlternatively, declare the delegate outside of the code for class A – then it will simply be another type you can reference by name (
SendInfo).