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
For methods inside the interface why can’t you specify the accessibility modifier?
Explain data types in c#?
Can we set image Source dynamically using C# in WPF application?
What are assemblies?
Which of the following API is used to hide a window?
What is fcl in c#?
What is the use of oops in c#?
What the different phase/steps of acquiring a proxy object in webservice?
Define c# delegate?
What is difference between event and delegate in c#?
What is a web service in c#?
Which one is trusted and which one is untrusted?
What is multithreading with .net?
How do you create user defined data types in c#?
What is the benefit of delegate in c#?