What is Interface Polymorphism?with E.g

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


Please Help Members By Posting Answers For Below Questions

What is difference between write and writeline in c#?

488


what is difference between destruct or and garbage collection ?

511


What is a lambda expression in c#?

512


Explain circular reference in c#?

548


Explain Direct CAST vs CType ?

556






Are all methods virtual in c#?

538


what is the difference between the debug class and trace class?

519


Distinguish between the Debug class and Trace class with its functionality?

534


Can we change static variable value in c#?

490


How do I run a cshtml file?

497


What is disco?

518


What is the C# syntax to catch any possible exception?

528


Explain the working of serialization?

488


Explain dataadapter.update method in .net?

518


What is inline function in c#?

512