I have a C # method that uses object as a generic container to return a data array that can be declared using different data types. The following is a simplified example of such a method:
void GetChannelData(string name, out object data) {
I need to convert all returned array elements to double , but so far I have not been able to find a way. Ideally, I would like to accomplish something like:
object objArray; GetChannelData("test", out objArray); double[] doubleArray = Array.ConvertAll<objArray.GetType().GetElementType(), double>(objArray, item => (double)item);
Which miserably fails because ConvertAll does not accept types defined at runtime. I also tried intermediate conversions to the dynamic variable, but to no avail.
Is there a way to do this type conversion in a simple way?
source share