c#讀取 txt文件存到數組裏面
阿新 • • 發佈:2017-08-23
ade dex ex18 ole cti collect ica nts double
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文件存到數組裏面