读取txt中的数据并保存在二维数组里,但是老是提示“无法将类型为“System.String[]”的对象强制转换为类型“System.IConvertible”.”
源代码如下
int[,] a = new int[20000, 8];
//选择文件并打开
openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
openFileDialog1.ShowDialog();
string Fname = openFileDialog1.FileName;
StreamReader SReader = new StreamReader(Fname, Encoding.Default); int i = 0; //用于标识数组行数
//将数据保存在数组里
string str = string.Empty;
while ((str = SReader.ReadLine()) != null)
{
for (int j = 0; j < 8; j++)
{
a[i, j] = Convert.ToInt32(str.Split(' '));
}
i++;
求大神帮忙看一下哪里错了,控件只需要一个button和一个openfiledialog即可读取文件出错
源代码如下
int[,] a = new int[20000, 8];
//选择文件并打开
openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
openFileDialog1.ShowDialog();
string Fname = openFileDialog1.FileName;
StreamReader SReader = new StreamReader(Fname, Encoding.Default); int i = 0; //用于标识数组行数
//将数据保存在数组里
string str = string.Empty;
while ((str = SReader.ReadLine()) != null)
{
for (int j = 0; j < 8; j++)
{
a[i, j] = Convert.ToInt32(str.Split(' '));
}
i++;
求大神帮忙看一下哪里错了,控件只需要一个button和一个openfiledialog即可读取文件出错
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货