Dave, I played about with your example. Very interesting.
The point is clear now. Thank you,
Adrian.
using System;
public class SamplesArray
{
public static void Main()
{
Type arrayType = Type.GetType("System.String");
new SamplesArray().DoStuff(arrayType);
}
//public void DoStuff(Type arrayType)
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,5, 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);
Console.Read();
}
else
{
Console.WriteLine("unknown Array Type: " +
unknownTypeArray.GetType().FullName);
Console.Read();
}
}
}