how to invoke event

  • Thread starter Thread starter somequestion
  • Start date Start date
S

somequestion

there are 2 class A and ALib
class A is general class
class ALib is library class
this class call each other...
A call Alib and then method of Alib call method of A....is it possible?
class is like below..
-------------------------------------------------------------------------
using ALib;
Class A
{
A();

funcA1()
{
// here!! use method of Class ALib
ALib alib = new ALib();
// When invoke funcALib of ALib i just wanna call fucnA2 on this
class(classA)
alib. funcALib();
}

funcA2(int a, int b)
{
// to do something
}

}
----------------------------------------------------------------------------
Class ALib
{
ALib();

funcALib()
{
// here!!!
// i just wanna call funcA2 of class A
// but how can i do this...
// should i use event or delegate??

A.funcA2(5,10); <--- i know it is impossible but how can i do this
??
}
}
 
Yes, it is possible, but you have to pass the reference (using this) to
the ALib instance to call back into.

If these classes are in separate assemblies though, you are going to
have an issue, because you will not be able to set references to each other,
so you will have to pass either an interface implementation (which is
defined in an assembly outside of the two) or an object and use reflection
to make the calls on the object.

Hope this helps.
 
yes, these classes are in separate assemblies...so...i really don't know how
can i solve it..
could you give me some code..for explain...


Nicholas Paldino said:
Yes, it is possible, but you have to pass the reference (using this) to
the ALib instance to call back into.

If these classes are in separate assemblies though, you are going to
have an issue, because you will not be able to set references to each
other, so you will have to pass either an interface implementation (which
is defined in an assembly outside of the two) or an object and use
reflection to make the calls on the object.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

somequestion said:
there are 2 class A and ALib
class A is general class
class ALib is library class
this class call each other...
A call Alib and then method of Alib call method of A....is it possible?
class is like below..
-------------------------------------------------------------------------
using ALib;
Class A
{
A();

funcA1()
{
// here!! use method of Class ALib
ALib alib = new ALib();
// When invoke funcALib of ALib i just wanna call fucnA2 on this
class(classA)
alib. funcALib();
}

funcA2(int a, int b)
{
// to do something
}

}
----------------------------------------------------------------------------
Class ALib
{
ALib();

funcALib()
{
// here!!!
// i just wanna call funcA2 of class A
// but how can i do this...
// should i use event or delegate??

A.funcA2(5,10); <--- i know it is impossible but how can i do this
??
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top