今天学习Net,发现Type.IsAssignableFrom(msdn位置:https://msdn.microsoft.com/zh-SG/library/system.type.isassignablefrom(v=vs.100))方法,不明白什么意思,上网查询了一下,理解如下:
Type.IsAssignableFrom 方法:确定当前的 Type 的实例是否可以从指定 Type 的实例分配,满足条件返回true;不满足条件返回false
例子:
Room room1 = new Room();
Kitchen kitchen1 = new Kitchen();
Type room1Type = room1.GetType();
Type kitchen1Type = kitchen1.GetType();
Console.WriteLine("room assignable from kitchen: {0}", room1Type.IsAssignableFrom(kitchen1Type));
意思是判断Room Type实例(room1Type)是否可以从Kitchen Type(kitchen1Type)实例中分派