Given an Array
argument to a function passed in as object
, how can I calculate its length in bytes?
I can get the number of elements as int L = (arg as Array).Length;
I've tried
Type t = (arg as Array).GetType().GetElementType();
int overallSize = sizeof(t);
This fails with:
The type or namespace name 't' could not be found (are you missing a using directive or an assembly reference?)