在下面的代码中,我将一个子类转换为一个基类,但 get 类型显示它仍然是子类的一个实例。这里发生了什么?
using System;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
Car c1 = new Car { m = "M", c = "C" };
Machine m1 = (Machine)c1;
Console.WriteLine(m1.GetType());//ConsoleApplication.Car
}
}
public class Machine
{
public string m;
}
public class Car : Machine
{
public string c;
}
}