如何确定数组的基础类型 [英] How do I determine the underlying type of an array
本文介绍了如何确定数组的基础类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
如何获取阵列NET中的数组类型中的项目类型
Possible Duplicate:
How do I get the Array Item Type from Array Type in .net
如果我有一个特定类型的数组,有没有办法分辨出该类型到底是什么?
If I have an array of a particular type is there a way to tell what exactly that type is?
var arr = new []{ "string1", "string2" };
var t = arr.GetType();
t.IsArray //Evaluates to true
//How do I determine it's an array of strings?
t.ArrayType == typeof(string) //obviously doesn't work
推荐答案
Type.GetElementType
- When overridden in a derived class, returns the Type of the object encompassed or referred to by the current array, pointer or reference type.
var arr = new []{ "string1", "string2" };
Type type = array.GetType().GetElementType();
这篇关于如何确定数组的基础类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文