(static member) (instance member). . , . , . . , .
, . const. C# const. , , , readonly.
C# , const.
. . , . .
, const, , . , .
readonly, .
public readonly int ScreenWidth;
public GraphicsPackageO { this.ScreenWidth = 1024; } }
, , , static readonly, . (static constructor) , .
class GraphicsPackage {
public static readonly int ScreenWidth;
static GraphicsPackageO { ScreenWidth = 1024; } }
, , . , , , . .
class TimePeriod
{ private double seconds;
public double Hours
{ get { return seconds / 3600; }
set { seconds = value * 3600; } }}
:
, .
get , set . .
|
|
value , set.
, set, .
, . , . C# . Main C#, CLR .
, public private, , abstract sealed, , . . . , .
abstract class Motorcycle
{ public void StartEngine()
protected void AddGas(int gallons)
public virtual int Drive(int miles, int speed); }
public abstract double GetTopSpeed(); }
- , . , .
class TestMotorcycle: Motorcycle
{ public override double GetTopSpeed() { return 108.4; }
static void Main()
{ TestMotorcycle moto = new TestMotorcycle();
double speed = moto.GetTopSpeed();
Console.WriteLine("My top speed is {0}", speed); }}