public static List <Car> ProcessCarFileByQueryMethod(string path) { var query = from l in File.ReadAllLines(path) .Skip(1) where l.Length > 1 select Car.ParseFromCsv(l); return(query.ToList()); }
private static List <Car> ProcessFile(string path) { var query = from line in File.ReadAllLines(path).Skip(1) where line.Length > 1 select Car.ParseFromCsv(line); return(query.ToList()); }
private static List <Car> ProcessFile(string path) { //Query syntax var query = from line in File.ReadAllLines(path).Skip(1) where line.Length > 1 select Car.ParseFromCsv(line); query.ToList(); // Inline projection File.ReadAllLines(path) .Skip(1) .Where(line => line.Length > 1) .Select(line => { var columns = line.Split(','); return(new Car { Year = int.Parse(columns[0]), Manufacturer = columns[1], Name = columns[2], Displacement = double.Parse(columns[3]), Cylinders = int.Parse(columns[4]), City = int.Parse(columns[5]), Highway = int.Parse(columns[6]), Combined = int.Parse(columns[7]) }); }) .ToList(); // Method syntax File.ReadAllLines(path) .Skip(1) .Where(line => line.Length > 1) .Select(line => Car.ParseFromCsv(line)) .ToList(); // Method syntax File.ReadAllLines(path) .Skip(1) .Where(line => line.Length > 1) .ToCar() .ToList(); // Method syntax return(File.ReadAllLines(path) .Skip(1) .Where(line => line.Length > 1) .Select(Car.ParseFromCsv) .ToList()); }