我想在下面的代码中获取一个字符串列表的列表,我得到的select是:
无法将类型'System.Data.EnumerableRowCollection>'隐式转换为'System.Collections.Generic.List>'
List<List<string>> rows = (from myRow in data.AsEnumerable()
select new List<string> {myRow["FirstName"].ToString(),
myRow["LastName"].ToString(),
myRow["Department"].ToString(),
myRow["Birthdate"].ToString(),
myRow["Description"].ToString()
});
Run Code Online (Sandbox Code Playgroud)
如何获取字符串列表?
Linq正在使用enumerables(IEnumerable).您需要转换为列表:
List<List<string>> rows = (from myRow in data.AsEnumerable()
select new List<string> {myRow["FirstName"].ToString(),
myRow["LastName"].ToString(),
myRow["Department"].ToString(),
myRow["Birthdate"].ToString(),
myRow["Description"].ToString()
}).ToList();
Run Code Online (Sandbox Code Playgroud)