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 ChoudharyRank #80 · 24.4K reputationPosted Mar 28, 2015, 6:42 AM EDT
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());
}
Tom MohanRank #912 · 2.3K reputationPosted Mar 28, 2015, 5:46 AM EDT
{
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 WadjeRank #19 · 47.2K reputationPosted Mar 28, 2015, 5:43 AM EDT
Guest User25 reputationPosted Mar 28, 2015, 1:52 PM EDT
Guest User25 reputationPosted Mar 28, 2015, 1:56 PM EDT