Hi Adrian,
public void DoStuff(Type arrayType)
{
// Here, Int32 is hard-coded
int[] intArray = null;
// Here, an Array of an unknown Type is created (late-bound)
Array unknownTypeArray = Array.CreateInstance(arrayType, 10);
// if we knew that arrayType was, for example, typeof(int)
// then we could cast our Array into an int[]:
if (unknownTypeArray is int[])
{
intArray = (int[]) unknownTypeArray;
Console.WriteLine("int[] length: " + intArray.Length);
}
else
Console.WriteLine("unknown Array Type: " + unknownTypeArray.GetType().FullName);
}
--
Dave Sexton
"Adrian <" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
>
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
>Hi Adrian,
<snipped>
Since I hard-coded typeof(int) its value may not be as apparent, but
imagine if a Type was passed
>into a method instead, for instance, and used as the argument to the
CreateInstance method.
Apologies for being so slow: could you please give an example? I don't
follow.
Adriam