Основы объектно-ориентированного программирования на языке C# book | Page 166

7 Класи get { return AmmountOfFloor; } } string IfloorNumber.this[uint index] { // реалiзацiя iндексатора get { if (index > -1 && index < floor.Length) return floor[index]; // код для отримання елементу else return "Wrong number of floor"; } set { floor[index] = value; // код для задання елементу } } } class Program { static void Main(string[] args) { ElevatorWithIndexer MyElevator = new ElevatorWithIndexer(3); IfloorNumber fN = MyElevator as IfloorNumber; if (fN != null) { fN[0] = "first"; fN[1] = "second"; fN[2] = "third"; } for (uint i = 0; i < fN.Size; i++) { Console.WriteLine("Number of floor is: {0}", fN[i]); } Console.ReadKey(); } } } Зауваження. Якщо є можливiсть виделити не лише спiльну спецi- фiкацiю, яле й реалiзувати спiльну функцiональнiсть, то необхiдно використовувати абстрактний клас. amsmath 166