C # read TXT file and write to a two-dimensional array (TXT data row, column unknown)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.