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
Why to use “using” in c#?
Is c# int immutable?
what is full assembly reference
What is generic delegates in c#?
What is an extension method in c#?
What are custom attributes in c#?
What do you mean by object pooling?
Do loops c#?
What is the meaning of MSIL?
What is a dbml?
What exactly is serverless?
what is collections in .net? why we use?
What is the difference between structure and class in c#?
Define c# delegate?
What is the use of delegate?