我试图将数据放入二维数组但是得到错误它将值添加到0,0位置然后是1.0位置等等,请使其正确
int count = output.Tables[0].Rows.Count;
string[,] terms = new string[count,2];
for (int runs = 0; runs < count; runs++)
{
terms[0,runs] =output.Tables[0].Rows[runs][0].ToString();
terms[0,runs] =output.Tables[0].Rows[runs][2].ToString();
}
Run Code Online (Sandbox Code Playgroud)
希望对你有所帮助..
也许这应该有用......
int count = output.Tables[0].Rows.Count;
string[,] terms = new string[count,2];
for (int runs = 0; runs < count; runs++)
{
terms[runs,0] =output.Tables[0].Rows[runs][0].ToString();
terms[runs,1] =output.Tables[0].Rows[runs][2].ToString();
}
Run Code Online (Sandbox Code Playgroud)
你已经定义了一个包含n行和2列的二维数组,但是在你的for循环中你已经对列进行了循环
terms[0,runs]
Run Code Online (Sandbox Code Playgroud)
所以你得到索引错误....