Hi, I have an Interface and I have a Class:
namespace Demo
{
public interface IAB
{
void Greet();
}
public class AB
{
public void Hello(IAB e )
{
e.Greet();
}
}
}
___________________________________________________________________________________
The problem is how do I implement the interface IAB as a parameter when I call the method Hello :
AB ab = new AB();
ab.Hello( how do I implement the interface inside here? ) ;
I know how to do it in Java using anonymous classes or lambda expression.
How can I do it in C#.
PLEASE HELP .......
Pankaj Kumar ChoudharyPosted Mar 28, 2015, 10:42 AM
public interface IAB
{
void Greet();
}
public class AB:IAB
{
public void Hello(IAB e)
{
e.Greet();
}
void IAB.Greet()
{
//Implement your code here
}
}
static void Main(string[] args)
{
AB Obj = new AB();
Obj.Hello(new AB());
}
Guest UserPosted Mar 28, 2015, 5:56 PM
Guest UserPosted Mar 28, 2015, 5:52 PM
Tom MohanPosted Mar 28, 2015, 9:46 AM
{
public interface IAB
{
void Greet();
}
public class AB
{
public void Hello(IAB e)
{
e.Greet();
}
}
public class abc : IAB
{
public void Greet()
{
throw new NotImplementedException();
}
}
public class c
{
public static void Main()
{
IAB inst = new abc(); ;
AB ab = new AB();
ab.Hello(inst);
}
}
}
I hope you got the solution .
Vithal WadjePosted Mar 28, 2015, 9:43 AM