首页 > 编程语言 > 详细

c#读取 txt文件存到数组里面

时间:2017-08-22 23:47:03      阅读:750      评论:0      收藏:0      [点我收藏+]
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]);
                }
            }
        }
    }
}

c#读取 txt文件存到数组里面

原文:http://www.cnblogs.com/sevensir/p/7414107.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!