usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.IO;namespacetwo-dimensional array {classProgram {Static voidMain (string[] args) { introw =0;//Line intCol =0;//LieFileStream FS; stringPath =@"C:\Documents and settings\administrator\ desktop \1.txt"; FS=NewFileStream (Path, FileMode.Open, FileAccess.Read); StreamReader SR; SR=NewStreamReader (FS); List<Double[]> arrary =Newlist<Double[]>(); while(!Sr. Endofstream) {string[] arr = Sr. ReadLine (). Split (' '); Col=arr. Length; Double[] temp=New Double[col]; for(intx =0; x < col; X + +) {Temp[x]=convert.todouble (arr[x]); } arrary. ADD (temp); for(inty =0; Y < col; y++) {Console.Write (Arrary[row][y]+" "); } row++; Console.WriteLine ("\ n"); } Sr. Close (); Fs. Close (); Console.read (); } }}
The arrary defines the type of the generic double array. is a method of using a two-dimensional array. The data can be read by arrary[x][y]. Note You must add each add once, and X will add 1.
If arrary is defined like this
list<double[,]> arrary = new list<double[,]>(); Then reading the data should be like this arrary[num][x,y] every time the add num will be +1, the add value must also be an object of [,].
C # read TXT file and write to a two-dimensional array (TXT data row, column unknown)