Determine if collection is of type IEnumerable

后端 未结 9 2026
轻奢々
轻奢々 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:10

    Since IEnumerable inherit IEnumerable (non generic) and if you don't need to know when a type is just IEnumerable and not IEnumerable then you can use:

    if (typeof(IEnumerable).IsAssignableFrom(srcType))
    

提交回复
热议问题