Не могу из расширенного метода класса наследника получить свойство этого самого наследника
Подскажите пожалуйста адекватное решение. Есть два класса.
Первый:
class Unit {
private string name;
private int? weight;
private byte[]? coordinates;
private static int count = 1;
public int? Weight {
get {
return weight;
}
set {
if (value == null || value <= 0) {
Console.WriteLine("Ошибка установки веса (" + value + ")! Должна быть > 0.");
weight = 1;
Console.WriteLine("Установленный вес " + name + " = " + value);
} else {
weight = value;
}
}
}
public string Name {
get { return name; }
private set {
if (value == null || value.Length == 0) {
Console.WriteLine("Ошибка установки имени (null)!");
name = "Default" + count;
count++;
Console.WriteLine("Установлено имя " + name);
} else {
name = value;
}
}
}
public byte[] Coordinates {
get { return coordinates; }
set { coordinates = value; }
}
public Unit(string name, int weight, byte[] coordinates) {
Name = name;
Weight = weight;
Coordinates = coordinates;
printInfo();
}
public virtual void printInfo() {
Console.WriteLine("\nMy name is " + Name + ".\nMy weight is " + Weight + ".\nMy coordinates is:");
Console.WriteLine("x : " + Coordinates[0] + "\ny : " + Coordinates[1] + "\nz : " + Coordinates[2]);
}
}
Второй, наследник:
class Player : Unit {
protected int health;
public int Health {
get { return health; }
set { health = value; }
}
public Player(string name, int weight, byte[] coordinates, int health) : base(name, weight, coordinates) {
Health = health;
}
public override void printInfo() {
base.printInfo();
Console.WriteLine("My health is " + this.health + "\n");
}
}
Проблема состоит в том, что когда я в основном коде создаю объекты вот так:
new Player("222", 2, new byte[] { 1, 2, 3 }, 100);
new Unit("111", 4, new byte[] { 1, 1, 1 });
Мой расширенный метод PrintInfo в классе Player после отработки родительского, а затем и своего собственного конструктора не записывает 100 в health, а почему-то записывает 0. Прошу прощения если мой вопрос банальный, не так давно взялся за C#