我的声明如下:
string[] lines = System.IO.File.ReadAllLines(file);
foreach (string line in lines)
{
...
}
Run Code Online (Sandbox Code Playgroud)
由于底层的.csv文件中有一个标题,这会导致我的错误.我想跳过这一行,但是当我使用时:
string [] lines = System.IO.File.ReadLines(file).Skip(1).ToArray();
Run Code Online (Sandbox Code Playgroud)
让我String无法使用Skip(1).当我尝试使用时同样的事情:
string[] lines = System.IO.File.ReadAllLines(file);
lines = lines.Skip(1).ToArray();
Run Code Online (Sandbox Code Playgroud)
给我带来同样的错误.
有谁有想法吗?我可以调整Foreach循环成为一个For循环,我解雇第一行?
问候,
编辑
我现在使用的代码是:
string[] lines = System.IO.File.ReadAllLines(file);
lines = lines.Skip(1).ToArray();
foreach (string line in lines)
{
var cols = line.Split(';');
if (cols.Length == 1)
continue;
DataRow dr = tbl.NewRow();
dr[0] = file;
for (int cIndex = 1; cIndex + 1 < tbl.Columns.Count; cIndex++) …Run Code Online (Sandbox Code Playgroud) 我有一个动物课:
public class Animals
{
public string Type { get; set; }
public string Gender { get; set; }
public int Amount { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
以及与不同动物相关的成本的类别成本:
public class Cost
{
public string AnimalType { get; set; }
public int Cost { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有一个不同类别的列表:
List<Animals> animalList = new List<Animals>()
{
new Animals() { Type = "Wolf", Gender = "Female", Amount = 10 },
new Animals() { Type = "Wolf", Gender = "Male", Amount = 20 }, …Run Code Online (Sandbox Code Playgroud)