using System;
//csc interface_property.cs
namespace calculate
{
//interface begins
interface Ical
{
//declare a variable
double area
//get property
{
get;
}
}
class clsCircle : Ical
{
// to hold the arguments to the methods
private double m_radius ;
//constructor
public clsCircle(double radius)
{
Console.WriteLine(" constructor for radius evoked ");
Console.WriteLine(" constructor received : " + radius);
m_radius= radius;
//constructor does not return
}
//property calculating area of circle
public double area
{
get { return (3.14 * m_radius * m_radius);}
}
//now return the calculated data to the caller
public override string ToString()
{
return("Area=" + area );
}
}
class test
{
static void Main()
{
Console.Write("Enter the radius of a circle ");
string str = Console.ReadLine();
double dd = double.Parse(str);
//feed value to the property
clsCircle cc = new clsCircle(dd);
Console.WriteLine(" Area of a circle " + cc);
}
}
//end of namespace
} |