我有一个传入数组,每行计数和一个字符串,该字符串表示一个或多个键的下划线拆分。
对于每个键,我想对总数进行分组并求和,如果键连续出现总共 5 个,则由下划线分割的每个项目的总数增加 5。
我只是想知道这将如何在 linq 中表示......
class Owl
{
public int SpeciesCount { get; set; }
public string BandIdentifier { get; set; }
}
public class GoOwl
{
public GoOwl(Owl[] owls)
{
//just making a list of test data to illustrate what would be coming in on the array
var owlList = new List<Owl>();
owlList.Add(new Owl { SpeciesCount = 2, BandIdentifier = "OWL1" });
owlList.Add(new Owl { SpeciesCount = 1, BandIdentifier = "OWL1_OWL2_OWL3" });
owlList.Add(new Owl { SpeciesCount = 2, BandIdentifier = "OWL3" });
owlList.Add(new Owl { SpeciesCount = 5, BandIdentifier = "OWL2_OWL3" });
//i'd ideally like to have something like a row for each band identifier split on underscore plus a total species count..
//where you'd sum the species count for each underscored item and group
}
}
以下将是作为单个 Owl 对象的所需输出
["OWL1", 3]
["OWL2", 6]
["OWL3", 8]
我还没有完全得到 SelectMany..
干杯