我正在尝试读取 .csv 文件,进行一些格式化,将每行拆分为其列数据并将新的分隔列数据数组添加到数组列表中。然后我想以不同的方式对列表进行排序。目前只是按用户名按字母顺序升序。
这是我到目前为止所尝试的:
// create list for storing arrays
List<string[]> users;
string[] lineData;
string line;
// read in stremreader
System.IO.StreamReader file = new System.IO.StreamReader("dcpmc_whitelist.csv");
// loop through each line and remove any speech marks
while((line = file.ReadLine()) != null)
{
// remove speech marks from each line
line = line.Replace("\"", "");
// split line into each column
lineData = line.Split(';');
// add each element of split array to the list of arrays
users.Add(lineData);
}
IOrderedEnumerable<String[]> usersByUsername = users.OrderBy(user => user[1]);
Console.WriteLine(usersByUsername);
这给出了一个错误:
使用未分配的局部变量“用户”
我不明白为什么它说它是一个未分配的变量?为什么我在 Visual Studios 2010 中运行程序时列表不显示?