=> We can define class members as static using the static keyword. When we declare a member is static it means no matter how many object of class created there is the only one copy of static member.
Static constructor called before calling instance constructor.
using System;
namespace StaticMember
{
class Circle
{
static float _pi =3.141F;
int _radius;
public Circle(int Radius)
{
this._radius = Radius;
}
public float calculateArea()
{
return Circle._pi * this._radius * this._radius;
}
}
class Program
{
static void Main(string[] args)
{
Circle C1 = new Circle(5);
float Area1=C1.calculateArea();
Console.WriteLine("Area= {0}", Area1);
Circle C2 = new Circle(6);
float Area2 = C2.calculateArea();
Console.WriteLine("Area= {0}", Area2);
Console.ReadLine();
}
}
}
0 comments:
Post a Comment