【发布时间】:2020-04-25 20:24:29
【问题描述】:
我正在尝试读取文本文件,然后将单词存储在二维数组中。我想要的是把这个:
a b c d e f g
h i j k l m n
o p q r s t u
变成
[ [a,b,c,d,e,f,g], [h,i,j,k,l,m,n], [o,p,q,r,s,t,u] ]
所以在一个数组内,每一行都有自己的数组,在该数组内,每个单词(在这种情况下只有字符)都是它自己的项目。
{
string[] lines = system.IO.File.ReadAllLines(@FilePath);
foreach (string line in lines)
{
//no idea what to put here
}
return contents;
}
【问题讨论】:
-
string[][] jaggedArray = lines.Select(x => x.Split(' ')).ToArray();
标签: c# arrays file jagged-arrays