我收到一個錯誤從下面的代碼中使用未分配的局部變量'multidimension'。我試圖通過分割他們把數據從文本文件返回多維數組中,並把每一行中的陣列使用未分配的局部變量'multidimension'
private void button1_Click_1(object sender, EventArgs e)
{
string[,] Lines;
//string[][] StringArray = null;
//to get the browsed file and get sure it is not curropted
try
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
{
string[] data= null;
string ReadFromReadLine;
while ((ReadFromReadLine = sr.ReadLine()) != null)
{
data = ReadFromReadLine.Split(',');
for (int i = 0; i <= ReadFromReadLine.Length; i++)
{
for (int j = 0; j <= data.Length; j++)
{
string[,] multidimensional;
multidimensional[i, j] = data[j];
}
}
}
//foreach(string s in Lines)
//{
// EditItemComboBox.Items.Add(s);
//}
}
FilePath.Text = openFileDialog1.FileName;
//textBox1.Text += (string)File.ReadAllText(FilePath.Text);
}
}
catch(IOException ex)
{
MessageBox.Show("there is an error" + ex+ "in the file please try again");
}
}
任何想法我做錯了嗎?
您在這裏要做什麼?不僅'multidimensional'永遠不會被分配,它也永遠不會被讀取。 – Dani
您是否試圖創建一個多維數組,每行有一行,每行上有一列?這就是它*看起來像你想要做的,但很難確定。 –