|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How do I get a Type instance that represents an array of a given Type instance?Hi,
I have the following scenario. (The example code is C#.) Type elementType = (given); Type arrayType = (an array of whatever type "elementType" represents); The question is, how do I get that value that's assigned to arrayType? The following code works, but it seems kludgy, since it involves a string parsing and lookup at runtime. Type arrayType = Type.GetType(elementType.FullName + "[]"); Does anyone know of a better way? Thanks, Jeff Brown Jeff,
> Type arrayType = Type.GetType(elementType.FullName + "[]"); That's the way to do it in v1.x of the framework. Note that you may> >Does anyone know of a better way? have to append the assembly name as well. In v2.0 there's a new Type.MakeArrayType() method for this. Mattias -- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. |
|||||||||||||||||||||||