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 satellite assemblies?
explain Garbage collector’s functionality on unmanaged code
Is it possible to restrict the scope of a field/method of a class to the classes in the same namespace?
What is interface inheritance in c#?
What is polymorphism c# example?
What type of data type conversion happens when the compiler encounters the following code?
What is private static in c#?
Whats an assembly? Describe the importance of assembly?
What is the use of jit ? Jit (just - in - time) is a compiler which converts msil code to
How to transpose multi-dimensional array?
What is c sharp language?
What is a template class?
Which is faster dictionary or hashtable?
How big is int16?
What is difference between ienumerable and list?