我有一个 System.Type 实例,“IsArray”返回 true。
如何判断数组类型的“嵌套类型”?
即
Type GetArrayType(Type t)
{
if(t.IsArray)
{
// What to put here?
}
throw new Exception("Type is not an array");
}
Assert.That(GetArrayType(typeof(string[])), Iz.EqualTo(typeof(string));
Assert.That(GetArrayType(typeof(Foo[])), Iz.EqualTo(typeof(Foo));
最佳答案
t.GetElementType()
关于c# - 如何使用反射来确定数组的嵌套类型(元素类型)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/840878/