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
Can You Prevent Your Class From Being Inherited By Another Class?
How many constructors can a class have in c#?
What is console based application?
Is c# and .net same?
What are strong name assemblies?
What is a .aspx file?
How can you reference current thread of the method ?
What is assembly version series sequence?
Is datetime immutable c#?
What are the commonly used i/o classes?
What can be done with c#?
How to find the current application file path while runtime?
What is a partial class. Give an example?
How do I unload an application domain?
The int maps to which C# keyword in .NET type?