Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace OOP_3Laba
- {
- public class Tree
- {
- public int age;
- public string name;
- public int height;
- public static int NumberOfObjects;
- //readonly поле
- public readonly int ReadOnlyField;
- //Конструктор по умолчанию
- public Tree()
- {
- age = 17;
- name = "OldOak";
- height = 300;
- NumberOfObjects++;
- }
- //Конструктор с параметрами
- public Tree(string _name, int _age, int _height)
- {
- name = _name;
- age = _age;
- height = _height;
- NumberOfObjects++;
- }
- //Статический конструктор
- static Tree()
- {
- }
- //Конструктор копирования
- public Tree(Tree obj)
- {
- name = obj.name;
- age = obj.age;
- height = obj.height;
- }
- //Деструктор
- //Закоментирован, т.к удаляет все объекты Tree
- //~Tree()
- //{
- // Console.WriteLine("Объект уничтожен");
- //}
- //Классический get и set
- public int SetTreeAge
- {
- get
- {
- return age;
- }
- set
- {
- if (value < 1)
- age = 1;
- else if (value > 500)
- age = 500;
- else
- age = value;
- }
- }
- //Автосвойство
- public int AutoSetAge
- { get; set; } = 1;
- //Метод GetInfo
- public void GetInfo()
- {
- Console.WriteLine($"Имя:{name} Возраст:{age} Высота:{height}");
- }
- //Переопределение
- public override int GetHashCode()
- {
- return base.GetHashCode();
- }
- public override string ToString()
- {
- return base.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement