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