C
CodeBlue
Hi,
(these are sample classes to illustrate)
I have 3 classes:
public class A
{
....
//array of 4 B objects
public B[4] B_Obj;
public A()
{
B_Obj = new B[4];
for (int i=0; i<4; i++)
B_Obj = new B();
}
public class B
{
public delegate void MyDelegate(int i);
public event MyDelegate OnFire;
public void ChangeValue(int x)
{
if (OnFire != null)
OnFire(x);
}
public class C
{
public A[] a = new A[10];
public C()
{
for (int x=0; x < 10; x++)
{
//init the A objects
A[x] = new A();
for (int y=0; y<4; y++)
{
//link all the B object events to one method
A[x].B_Obj [y].OnFire += new B.MyDelegate(B_Event_Raised);
}
}
//try to fire the event
A[0].B_Obj[0].ChangeValue(1);
}//end C constructor
public void B_Event_Raised(int x)
{
....
}
}
///////////////////////////////////////////////
However, in the above code, B_Event_Raised never gets called, and the
OnFire event always returns null. How come this is the case, when the
event handler is linked in C???
Regards,
Alex
(these are sample classes to illustrate)
I have 3 classes:
public class A
{
....
//array of 4 B objects
public B[4] B_Obj;
public A()
{
B_Obj = new B[4];
for (int i=0; i<4; i++)
B_Obj = new B();
}
public class B
{
public delegate void MyDelegate(int i);
public event MyDelegate OnFire;
public void ChangeValue(int x)
{
if (OnFire != null)
OnFire(x);
}
public class C
{
public A[] a = new A[10];
public C()
{
for (int x=0; x < 10; x++)
{
//init the A objects
A[x] = new A();
for (int y=0; y<4; y++)
{
//link all the B object events to one method
A[x].B_Obj [y].OnFire += new B.MyDelegate(B_Event_Raised);
}
}
//try to fire the event
A[0].B_Obj[0].ChangeValue(1);
}//end C constructor
public void B_Event_Raised(int x)
{
....
}
}
///////////////////////////////////////////////
However, in the above code, B_Event_Raised never gets called, and the
OnFire event always returns null. How come this is the case, when the
event handler is linked in C???
Regards,
Alex