Hi all experts ...
I have a question ....

How can i call a function of Class A from Class B without creating any objects,static menthds or using any inheritance..
like if class A has a variable of classB then classB can call a method of class A....
explanatory code:

class A 
{ 
method A () 
//how to define Var of Class B 
} 
class B 
{ 
// how to call method of class A here
}

Thanks and regards ...

Edited 4 Years Ago by gemini88: code change

What exactly are you trying to do just use a function within it? you can inject it as a parameter

Class A 
 {
  public A (B instance)
    {
    B.SomeMethod;
    }
 }

 Class B 
 {
  SomeMethod()
   {
   Console.WriteLine("injected");
   }
 }

or you can use get set method with property look into dependency injection

you can also use an interface too, if for whatever reason you dont wanna inherit it or use an abstract class

Edited 4 Years Ago by grh1107

Thanks but the code gives compilation error ...

Important thing to add here is that i want to use such way which doesnot require me to call method by writing class name like B.SomeMethod. i want to directly call "SomeMethod;"

Edited 4 Years Ago by gemini88: addition

try this?

class A
{
    public void methodA()
    {
        Console.Write("This text is by methodA in Class A");
    }
}

class B
{
    public void methodB()
    {
        A Aobj = new A();
        Aobj.methodA();
    }
}

Thanks but i have mentioned earlier that i dont have to use objects or static methods.
i want to implement a logic which doesnot require using classname.methodname rather can be called directly without classname.

Thnaks all....
i have found the answer, that is DELEGATES.
the one who dont know must read to have advanced knowlegde.

This question has already been answered. Start a new discussion instead.