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 are console applications used for?
What is int32?
Are private members inherited in c#?
What's the difference between a static method and a non static method c#?
What is difference between throw and throws in c#?
What is dapper in c#?
Describe a Struct ?
What do u mean by thread safe?
What is c# commonly used for?
What is a nullreferenceexception?
Why do we use public static void main in c#?
When should we use sealed class in c#?
What is the difference between malloc () and new?
Explain the use of SN.exe
How to update the gui from another thread in c#?