如何判断类型是列表还是数组或 IEnumerable 或 [英] How to tell whether a Type is a list or array or IEnumerable or
本文介绍了如何判断类型是列表还是数组或 IEnumerable 或的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个 Type
对象,测试它是否实际上是一个对象列表的最简单方法是什么?IE.数组或 IEnumerable/IEnumerable<>.
What's the easiest way, given a Type
object, to test to see whether it is actually a list of objects? I.e. Array or IEnumerable/IEnumerable<>.
推荐答案
检查 typeof(IEnumerable).IsAssignableFrom(type)
.
每个集合类型,包括数组和IEnumerable
,都实现了IEnumerable
.
Every collection type, including arrays and IEnumerable<T>
, implements IEnumerable
.
这篇关于如何判断类型是列表还是数组或 IEnumerable 或的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文