c#讀取 txt文件存到數組里面


using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.IO;
 
namespace  ConsoleApplication1
{
     class  Program
     {
         static  void  Main( string [] args)
         {
             
             StreamReader rd = File.OpenText( "data.txt" );
             string  s = rd.ReadLine();
             string [] ss = s.Split( ',' );
             
             int  row =  int .Parse(ss[0]);  //行數
             int  col =  int .Parse(ss[1]);   //每行數據的個數
 
             double [,] p1 =  new  double [row,col];  //數組
             
             for  ( int  i = 0; i < row; i++)   //讀入數據並賦予數組
             {
                 string  line = rd.ReadLine();
                 string [] data = line.Split( ',' );
                 for  ( int  j = 0; j < col; j++)
                 {
                     p1[i, j] =  double .Parse(data[j]);
                 }
             }
         }
     }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM