logo
CSharp_Prog_Guide

Рассмотрение кода

Далее перечислены важные замечания по предыдущему примеру:

((Employee)m1).Name = "Mary";

Example 3

Description

In this example, two classes, Cube and Square, implement an abstract class, Shape, and override its abstract Area property. Note the use of the override modifier on the properties. The program accepts the side as an input and calculates the areas for the square and cube. It also accepts the area as an input and calculates the corresponding side for the square and cube.

Code

abstract class Shape

{

public abstract double Area

{

get;

set;

}

}

class Square : Shape

{

public double side;

public Square(double s) //constructor

{

side = s;

}

public override double Area

{

get

{

return side * side;

}

set

{

side = System.Math.Sqrt(value);

}

}

}