The problem isn’t that you are trying to convert it to an object array, but
that you are never successfully converting it to a DateTime array in the
first place.
For your ToArray, instead of:
list.ToArray(typeof(DateTime));
Try:
list.ToArray(typeof(DateTime[]));
Once you’ve got the correct type of array being generated (or an array
period for that matter, then you can freely convert the resulting array to
any compatible sort, leaving you with:
object[] objArray = (object[]) list.ToArray(typeof(DateTime[]));
Brendan
"Brian P" wrote:
I am getting an invalid cast exception when I try
to take an ArrayList with datetime values and use
the ToArray method to create an object array.
I need to use an object array becase I'm working
with various datatypes and need the code to
be as generic as possible.
Most of to code involves dynamically determining
the datatype, which all works.
The code that fails is where I already know the
type is date time:
object[] objArray = (object[]) list.ToArray(typeof(DateTime));
How can I get an array of date time objects into an object array??
Thanks for any help,
Brian