Hi Guys
NP70 readonly Keyword
http://www.java2s.com/Code/CSharp/Language-Basics/Demonstratetheuseofreadonlyvariables.htm
I got this program from the above website. Reserved Keyword readonly has been used in the program. Program is producing similar output without readonly Keyword. I wish to know in this circumstance what is the purpose of using readonly Keyword.
Anyone knows please explain the reason.
Thank you
namespace nsReadOnly
{
using System;
public class ReadOnly
static double DegreeFactor = 1;
static double MilFactor = 0.05625;
static public void Main()
double degrees = 42;
// 1 degree = 17.77778 mils
double mils = degrees * 17.77778;
// 1 degree = 0.017453 radians
double radians = degrees * 0.017453;
clsArea InDegrees = new clsArea(DegreeFactor);
InDegrees.Angle = degrees;
InDegrees.Radius = 50;
Console.WriteLine("Area of circle is {0,0:F1}", InDegrees.Area);
// Radians are the default, so you can use the parameterless
// constructor
clsArea InRadians = new clsArea();
InRadians.Angle = radians;
InRadians.Radius = 50;
Console.WriteLine("Area of circle is {0,0:F1}", InRadians.Area);
clsArea InMils = new clsArea(MilFactor);
InMils.Angle = mils;
InMils.Radius = 50;
Console.WriteLine("Area of circle is {0,0:F1}", InMils.Area);
}
class clsArea
private const double pi = 3.14159;
private const double radian = 57.29578;
private readonly double m_Factor = 1;
private double m_Angle;
private double m_Radius;
public clsArea()
public clsArea(double factor)
m_Factor = factor / 57.29578;
public double Angle
get { return (m_Angle); }
set { m_Angle = value; }
public double Radius
get { return (m_Radius); }
set { m_Radius = value; }
public double Area
get
return (m_Radius * m_Radius * pi * m_Angle * m_Factor / (2 * pi));
/*
Area of circle is 916.3
Press any key to continue . . .
*/