weight = new int[N, N]; //加权矩阵
string[] lines = System.IO.File.ReadAllLines(@"F:\1.txt");
int i = 0;
char c = ' ';
foreach (string line in lines) //按行读取为字符串数组
{
string[] arr = line.Split(c);
for(int j=0; j<arr.Length; j++)
{
int w = int.Parse(arr[j]); //字符串转数字
weight[i, j] = w;
}
i++;
}
c#---读文件
最新推荐文章于 2024-04-29 10:08:36 发布