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 the drawbacks of extending an interface as opposed to extending a class?
What is the use of oops in c#?
What is _viewstart cshtml?
What is indexer c#?
Give an example of removing an element from the queue?
Is it possible to force garbage collector to run?
What are the steps to create a webservice and consume it?
What are Regex / regular expressions ?
How many bytes is an int?
What is the difference between null and string empty in c#?
List the 5 different access modifiers in c#?
What is the difference between C# 3.5 and C# 4.0?
How to handle exceptions that are raised in a component?
What is jit? What are the different types of jit?
Is string a data type in c#?