Reputation: 11
I have two classes class A and B.I have a delegate n event published in class B.The class B object is declared in class A.All he functionality dependes on the parameterised constru ctor of class B. Before initializing the object of class B i need to subscibe the event for it.how to do it? e.g
public class B
{
public delegate void myDel(string);
public event myDel myEvent;
B(object obj)
{
-----------------
------------------
}
}
class A
{
A objA;
class XYZ objXYZ;
void func()
{
objA.myEvent+=new myDel();
objA=new A(objXYZ); // hw to attain this?
}
}
Upvotes: 1
Views: 240
Reputation: 3136
You can't attach events or use members on not instantiated objects. Attach your event handler after object initialization
Upvotes: 2