
Example: Csharp program for
demonstrating interface for calculating area’s of circle and square based on
choice


/*Csharp program for demonstrating interface for calculating area’s of
circle and square based on choice*/
using System;
public interface Area
{
void AreaofCircle();
void AreaofSquare();
}
public class MainClass : Area
{
public static void Main(String[] args)
{
MainClass M=new MainClass();
int choice;
Console.WriteLine("Enter 1 to
find area of Circle");
Console.WriteLine("Enter 2 to
find area of Square");
Console.Write("Your choice :
");
choice =
Int32.Parse(Console.ReadLine());
if(choice==1)
{
M.AreaofCircle();
}
else if(choice==2)
{
M.AreaofSquare();
}
else
{
Console.WriteLine("Wrong
Choice..");
}
}
public void AreaofCircle()
{
int r;
double pi=3.14;
double area;
Console.Write("Enter radius
of circle to find the area :");
r =
Int32.Parse(Console.ReadLine());
area=pi*r*r;
Console.WriteLine("Area of
Circle is : "+area);
}
public void AreaofSquare()
{
int side;
double area;
Console.Write("Enter side of
square to find the area :");
side =
Int32.Parse(Console.ReadLine());
area=side * side;
Console.WriteLine("Area of
Square is : "+area);
}
}

Output

Enter 1 to find area of Circle
Enter 2 to find area of Square
Your choice : 2
Enter side of square to find the area :5
Area of Square is : 25
Enter 1 to find area of Circle
Enter 2 to find area of Square
Your choice : 1
Enter radius of circle to find the area :10
Area of Circle is : 314
