arrays - convert string[] to doube[,] in C# -


I have a text file that includes data:

  1,2 2,3 3, 4 4,5   

Now I want to save the data to an array. So I divide:

 using  (streamer sr = new streamreader ("file.txt")) {string [] data = sr.ReadLine (). Split (','); }   

Although my data was saved in the string [] while I declared globaldataClass array as double [,] has gone. Something like this:

  Fixed class globalDataClass {public static double [,] array = new double [4, 2]; }   

I need to assign data to GlobalDataClass:

  GlobalDataClass.Array = data;   

So my question is that string [] to double [,] ?

Since you have a 2-D array, so you can iterate on each row and remove the values If necessary, then specify it in the appropriate position. You can repeat select and . By using

  (var reader = new streamReader ("file .txt")) {string string; (Var count = 0; count & lt; 4; ++ count) {var data = reader.ReadLine (). Sample (','). Select (v = & gt; double. Purse (v)) .oir (); GlobalDataClass.Array [calculation, 0] = data [0]; GlobalDataclass.Array [calculation, 1] = data [1]; }}   

Now if your array was actually double [] [] , then you can do something like:

 < Code> GlobalDataClass.Array = File.ReadAllLines ("file.txt"). Select (L = & gt; L. Split (','). Select (v = & gt; Double Purs (v)) .Oir ()) .Oir ();   

Note: I think it is a very bad idea to make a global variable. There is probably a better way to handle this.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -