Home All Groups Group Topic Archive Search About

Getting Array Type From Type

Author
28 Jun 2006 11:21 PM
gary
Currently I am doing the following to find an one dimensional array
type of a type -

Type asSingle;

Type asArray = Array.CreateInstance ( asSingle , 0 ).GetType ( );


Is there a way to do this without creating an instance?

I do not know the array type at design time.


Thanks in advance,

Gary

Author
29 Jun 2006 12:07 AM
Chris Chilvers
Show quote
On 28 Jun 2006 16:21:07 -0700, "gary" <gbre***@gmail.com> wrote:

>Currently I am doing the following to find an one dimensional array
>type of a type -
>
>Type asSingle;
>
>Type asArray = Array.CreateInstance ( asSingle , 0 ).GetType ( );
>
>
>Is there a way to do this without creating an instance?
>
>I do not know the array type at design time.
>
>
>Thanks in advance,
>
>Gary

What about (assuming .net 2):

asSingle.GetType().MakeArrayType();
Author
29 Jun 2006 12:33 AM
gary
Chris Chilvers wrote:
Show quote
> On 28 Jun 2006 16:21:07 -0700, "gary" <gbre***@gmail.com> wrote:
>
> >Currently I am doing the following to find an one dimensional array
> >type of a type -
> >
> >Type asSingle;
> >
> >Type asArray = Array.CreateInstance ( asSingle , 0 ).GetType ( );
> >
> >
> >Is there a way to do this without creating an instance?
> >
> >I do not know the array type at design time.
> >
> >
> >Thanks in advance,
> >
> >Gary
>
> What about (assuming .net 2):
>
> asSingle.GetType().MakeArrayType();

Superb. Thanks Chris.

AddThis Social Bookmark Button