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 abstract class have constructor c#?
Can abstract class be sealed?
Why do you call it a process? What’s different between process and application in .net, not common computer usage, terminology?
What is difference between struct and class in c#?
Can a class or a struct have multiple constructors?
Which is faster dictionary or list?
What is a interface in c#?
How objects are stored in memory?
What is 8 bit signed integer?
What is difference between il and dll ?
What is the data type for bit in c#?
What are the Types of values mode can hold session state in web.config
How do you prevent a method from being overridden in c#?
What are modifiers in c#?
What is the difference between a variable and a literal?