我想确定某个对象是从 派生的IEnumerable,但反射说List<int>不是 的子类IEnumerable。
https://dotnetfiddle.net/an1n62
var a = new List<int>();
// true
Console.WriteLine(a is IEnumerable);
// falsa
Console.WriteLine(a.GetType().IsSubclassOf(typeof(IEnumerable)));
Console.WriteLine(a.GetType().IsSubclassOf(typeof(IEnumerable<>)));
Console.WriteLine(a.GetType().IsSubclassOf(typeof(IEnumerable<int>)));
is关键字可以找到,但我必须在没有关键字的情况下解决这个问题。
慕田峪7331174
相关分类