Type.GenericTypeArguments属性和Type.GetGenericArguments()方法之间有什么区别?他们总是返回相同的东西还是在某些情况下有所不同?

最佳答案

typeof(List<>)是一个不同之处的示例。 property返回一个空数组,而method返回其中包含通用T的数组。 (此T具有 IsGenericParameter true)

通过阅读文档,我认为您可以将GenericTypeArguments视为GetGenericArguments().Where(t => !t.IsGenericParameter).ToArray(),即仅将具体类型视为。另请参见 ContainsGenericParameters

关于c# - Type.GenericTypeArguments属性与Type.GetGenericArguments()方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19503905/

10-11 04:10