I am new to C# (and OOP). When I have some code like the following:
class Employee
{
// some code
}
class Manager : Employee
{
//some code
}
Question 1: If I have other code that does this:
Manager mgr = new Manager();
Employee emp = (Employee)mgr;
Here Employee
is a Manager
, but when I cast it like that to an Employee
it means I am upcasting it?
Question 2:
When I have several Employee
class objects and some but not all of them are Manager
's, how can I downcast them where possible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…