Answer Posted / sandeep negi
//Consider IShape interface like this
interface IShape
{string CalculateArea();}
class Circle : IShape
{
public string CalculateArea(){return "Circle area";}
}
class Rectangle : IShape
{
public string CalculateArea(){return "Rectangle
area";}
}
//implement function
private string ProcessArea(IShape shape)
{return shape.CalculateArea();}
//call this function from main or from button click event
like this
private void button1_Click(object sender, EventArgs e)
{
Rectangle r = new Rectangle();
Circle c = new Circle();
MessageBox.Show(ProcessArea(r));
MessageBox.Show(ProcessArea(c));
}
Is This Answer Correct ? | 3 Yes | 2 No |
Post New Answer View All Answers
What is difference between write and writeline in c#?
what is difference between destruct or and garbage collection ?
What is a lambda expression in c#?
Explain circular reference in c#?
Explain Direct CAST vs CType ?
Are all methods virtual in c#?
what is the difference between the debug class and trace class?
Distinguish between the Debug class and Trace class with its functionality?
Can we change static variable value in c#?
How do I run a cshtml file?
What is disco?
What is the C# syntax to catch any possible exception?
Explain the working of serialization?
Explain dataadapter.update method in .net?
What is inline function in c#?