将数据表转换为私有List >?(Convert datatable to private List>?)
有什么快速的方法可以将数据List<List<string>>转换为List<List<string>> ?
现在我正在做
for (int rowIndex = 1; rowIndex <= stats.EndRowIndex; rowIndex++) { List<string> lstOneRowElements = new List<string>(); for (int colIndex = 1; colIndex <= stats.EndColumnIndex; colIndex++) { lstOneRowElements.Add(excelDoc.GetCellValueAsString(rowIndex, colIndex).Trim()); } lstAllData.Add(lstOneRowElements); }哪里
private List<List<string>> lstAllData { get; set; }有什么更好的方法快速完成吗?
Any fast way to convert a datatable to List<List<string>> ?
right now i am doing
for (int rowIndex = 1; rowIndex <= stats.EndRowIndex; rowIndex++) { List<string> lstOneRowElements = new List<string>(); for (int colIndex = 1; colIndex <= stats.EndColumnIndex; colIndex++) { lstOneRowElements.Add(excelDoc.GetCellValueAsString(rowIndex, colIndex).Trim()); } lstAllData.Add(lstOneRowElements); }where
private List<List<string>> lstAllData { get; set; }any better way to do it fast ?
最满意答案
如果您有DataTable(请参阅评论Mithon),那么您可以试试这个
var q = from row in dt.AsEnumerable() select row.ItemArray.Select(x => x.ToString()).ToList<string>(); var y = q.ToList();If you have a DataTable (see comment Mithon) then you can try this
var q = from row in dt.AsEnumerable() select row.ItemArray.Select(x => x.ToString()).ToList<string>(); var y = q.ToList();更多推荐
发布评论