Determine if collection is of type IEnumerable

后端 未结 9 2027
轻奢々
轻奢々 2020-12-12 23:50

How to determine if object is of type IEnumerable ?

Code:

namespace NS {
    class Program {
        static IEnumerable GetInts()         


        
9条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 00:27

    i is of type NS.1.Program+d__0, which is a subtype of IEnumerable. Thus, you can use either

    if (i is IEnumerable) { ... }
    

    or IsAssignableFrom (like in Marc's answer).

提交回复
热议问题