array's type

  • Thread starter Thread starter frisco
  • Start date Start date
F

frisco

by reflection I can infer that a property is Array type.
But how I can get the type the array is composed from?

for instance:

string[] table;

I want to get String and not Array

thank you
 
Hi...Just check the type of the first element:

static void Main(string[] args) {
string[] foo = new string[3];
foo[0] = "apple";
foo[1] = "peach";
foo[2] = "pear";
Console.WriteLine("typeof(foo) = {0}", foo.GetType().ToString());
Console.WriteLine("element type = {0}", foo[0].GetType().ToString());
}

John Puopolo
 
frisco said:
by reflection I can infer that a property is Array type.
But how I can get the type the array is composed from?

for instance:

string[] table;

I want to get String and not Array

table.GetType().GetElementType()
 
you should be able to infer more than just the property being Array type.
but rather the specific type that's derived from Array type. in your case,
your property type should be System.String[]. and you can do what Daniel
O'Connell suggested by calling GetElementType to get System.String. If you
only have System.Array as your type, GetElementType will not work.
 
Back
Top