Stock();
Asset a = msft; // upcast
Console.WriteLine(a == msft);
Console.WriteLine(a.Name);
Console.WriteLine();
// downcast
Stock s = (Stock)a; // downcast
Console.WriteLine(s == msft);
Console.WriteLine(a == msft);
Console.WriteLine(s.SharesOwned);
why after downcasting a which is parent object, I cannot access child's property? I mean why I cannot use a.ShareOwned? SharesOwned is child's property
s is the result of downcast. s.SharesOwned work, doesn't it?
Обсуждают сегодня