Answer the question
In order to leave comments, you need to log in
How to convert string[] array to double[] array?
Good afternoon!
I am writing a method that receives 2 string[] arrays as input. I need to convert a string to a double (or int), and I already know that only numbers are real there, but VS gives an error Cannot implicitly convert type 'int' to 'string'
Here is the code:
private void GrathMath(string[] x, string[] y)
{
for (int i = 0; i<x.Length; i++)
{
x[i] = double.Parse(x[i]);
}
}
Answer the question
In order to leave comments, you need to log in
Greetings.
Here is the answer on the msdn forum .
double [] doubleArray = new double[stringArray.Length]
for(int i=0; i<stringArray.Length; i++)
{
doubleArray[i] = Double.Parse(stringArray[i]);
}
double[] doubleArray = stringArray.Select<string, double>(s => Double.Parse(s)).ToArray<double>();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question