dimanche 31 mars 2019

List

I want to determine some object is derived from IEnumerable, but Reflection says List<int> is not a subclass of 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 keyword works find, but I have to sovle this without the keyword.





Aucun commentaire:

Enregistrer un commentaire