Converting string arrays to double

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I was wondering if it is possible to convert an array that is of type string
to type double so that matrix operations can be performed on it? I have a
string array because I needed to split the array before performing any
operations on it. Thanks!!
 
Hi Christine,

Nothing elegant:

string[,] strVals = { {"1.1", "1.2"}, {"2.1", "2.2"} };

int maxRow = strVals.GetUpperBound(0);
int maxCol = strVals.GetUpperBound(1);

double[,] dblVals = new double[maxRow+1, maxCol+1];

for (int i=0; i <= maxRow; i++)
{
for (int j=0; j <= maxCol; j++)
{
dblVals[i, j] = double.Parse(strVals[i, j]);
}
}

Joe
 
Back
Top