use unassigned local variable 'multidimension'

萝らか妹 提交于 2019-11-29 18:14:41
string[,] multidimensional;

should be:

string[,] multidimensional = new string[ReadFromReadLine.Length, data.Length];

and moved out of the for loops and maybe sent to a method, cached, or something

You are just defining an array called 'multidimensional', but not assigning it to anything.

for (int j = 0; j <= data.Length; j++ )
{
    string[,] multidimensional = new String[i,data.Length]
    multidimensional[i, j] = data[j];
}

However, I am not sure I am following what you are trying to do in the innermost loop. You are defining a new array called 'multidimensional' each time you are looping through the elements in data and the old data is lost each time.

If 'multidimensional' is suppose to contain the contents of the entire file, you need to define it outside of the first loop, but to use an array like you are, you need to know the number of lines in your file. If you are using C#2 or greater, a List<> would be a better choice

var list = new List<String[]>();

while ((ReadFromReadLine = sr.ReadLine()) != null)
{
    data = ReadFromReadLine.Split(',');
    list.Add(data);        
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!