How do I get the Array Item Type from Array Type in .net

后端 未结 3 1372
清酒与你
清酒与你 2020-12-09 00:54

Say I have an System.String[] type object. I can query the type object to determine if it is an array

Type t1 = typeof(System.String[]);
bool i         


        
3条回答
  •  再見小時候
    2020-12-09 01:05

    You can use the instance method Type.GetElementType for this purpose.

    Type t2 = t1.GetElementType();
    

    [Returns] the type of the object encompassed or referred to by the current array, pointer, or reference type, or null if the current Type is not an array or a pointer, or is not passed by reference, or represents a generic type or a type parameter in the definition of a generic type or generic method.

提交回复
热议问题