有什么区别:
typeof(IInterface).IsAssignableFrom(typeof(Class));
和
typeof(Class) is IInterface
?
编辑:对于上下文,我的功能是这样的:
public static List<T> GetAllInstancesOfType<T>() where T:Entity
{
List<T> l = new List<T>();
if (typeof(IMyInterface).IsAssignableFrom(typeof(T)) //or (typeof(T) is IMyInterface)
foreach(Entity e in List1) if (e is T) l.Add(e as T);
else foreach (Entity e in List2) if (e is T) l.Add(e as T);
return l;
}