c# - LINQ First() or Single() parameter -
trying sorted data csv file. code works fine except "side" column string , same 1 group. can't figure out parameter should single() of first() methods.
var stuff = line in file.readlines(@"d:\tmp\4.csv").skip(1) let columns = line.split(';') select new { time = columns[0], side = columns[2], qty = columns[3], symbol = columns[4], price = columns[5], }; var sorted = line in stuff group line new { line.time, line.symbol } category select new { category.key.time, category.key.symbol, qty = category.sum(p => int32.parse(p.qty)), price = category.average(p => double.parse(p.price)), side = ?????? };
single
throw exception if finds more 1 record, think not want
first
select first record list, both single
, first
throw 'invalidoperationexception' exception if collection empty.
so use firstordefault
here
side = category.select(p => p.side).firstordefault()
Comments
Post a Comment