我正在加载CSV文件
分为:
var records = csvLinesData.Select(data => new ReleaseVersion
{
Version = data[0],
ReleaseDate = TryParse(data[1]),
// add list of ReleaseNote ??
}).ToList();
如何按版本和 ReleaseVersion 的返回列表对所有记录进行分组?
这是我所做的,但我不知道如何按第一列分组,即文件中的版本列。
base R
答案 0 :(得分:4)
第一项只需GroupBy
:
DateTime date;
var records = csvLinesData
.GroupBy(line => line[0]) // line[0] is version we want to group by on
.Select(chunk => new ReleaseVersion() {
Version = chunk.Key,
ReleaseDate = DateTime.TryParse(chunk.First()[1], out date)
? (DateTime?) date
: null,
ReleaseNotes = chunk
.Select(item => new ReleaseNote() {
Description = item[2],
Progress = item[3],
Status = item[4], })
.ToArray(), })
.ToList();