Convert a string array to a double array

Hi,
I get the error:

Unable to cast object of type system.string to type system.IConvertible.

Likely it was because of my assign:

outlier_numeric= {Convert.ToDouble(outlier_value)}
outlier_value is an array of string, and I want to convert to an array of double.

How do I solve this?
Thank you

Hi,

You need to use For each loop to convert type one by one, or use the following expression.

outlier_numeric = outlier_value.Select(function(x) Convert.ToDouble(x)).toArray()

Regards,

1 Like

Hi,
Thank you. What does the “x” in the argument stand for?
I get the error:

Input string is not in correct format

Hi,

function(x) and x mean Anonymous function for VB.net.

Input string is not in correct format

This means your data is not valid as double type such as containing non-numeric character (alphabet, linebreak etc.). Can you check your data?

Regards,

@Anonymous2 Can you try using this Statement:
outlier_value.Select(function(x) if(String.IsNullOrEmpty(x.Trim) Or String.IsNullOrWhiteSpace(x.Trim),0,Convert.ToDouble(x))).toArray()

1 Like