你好家伙我正在阅读一个本地csv文件至极有数据,我最终将使用加载到数据库。我的问题很简单,但我似乎无法理解这个概念。以下是我的代码。很简单的东西。不能将字符串添加到字符串c的列表#
static void loadTables() {
int size = new int();
string[] empid = new string[0];
//string[] empid = new string();
List<string[]> EmployeeName = new List<string[]>();
List<string[]> EmployeeId = new List<string[]>();
List<string[]> Group = new List<string[]>();
List<string[]> Org = new List<string[]>();
List<string[]> Fund = new List<string[]>();
try {
using (StreamReader readFile = new StreamReader("C:\\temp\\groupFundOrgReport.csv"))
{
string line;
string[] row;
size = 0;
while ((line = readFile.ReadLine()) != null)
{
row = line.Split(',');
/*resize the array up by 1*/
Array.Resize(ref empid,empid.Length+1);
/*im using size as a counter to add to the slot on the array.*/
empid[size] = row[0].Remove(0,1);
// here i reciever error (the best overload match of system generic list?...etc)
EmployeeName.Add(row[0]);
size++;
}
}
}
catch(Exception e){
Console.WriteLine(e);
}
}
我有一个字符串列表,但任何尝试向它添加一个字符串都会给我一个错误。换句话说,如果我尝试这样做EmployeeName.Add(row [0] .ToString);我收到一个错误。但是,如果我评论线,我可以使用旧的时尚阵列。我真的很喜欢使用列表,但我似乎无法传递我想要的值。有人可以请我指出正确的方向。
在此先感谢 米格尔
我自己也尝试** EmployeeName.Add(行[0]); **,没有运气 – Miguel
是不是行[0]单字符串 - 不是一个字符串[]? –
错误'System.Collections.Generic.List .Add(string [])'的最佳重载方法匹配有一些无效参数 –
Miguel