【问题标题】:Get object from LIst<> with minimal property count [duplicate]从 LIst<> 获取具有最少属性计数的对象 [重复]
【发布时间】:2015-07-23 17:19:19
【问题描述】:

我有一个这样定义的对象:

class BFull
{
    public string ImageName { get; set; }
    public List<BPart> PartsList { get; set; }
    public bool Processed { get; set; }
}

在其他方法中,我有一个列表List&lt;BFull&gt; Fulls,我需要从Fulls 中选择一个BPart 数量最少的BFull

【问题讨论】:

    标签: c#


    【解决方案1】:

    你可以使用...

    BFull minBFull = Fulls.OrderBy(x => x.PartsList.Count).First();
    

    如果你想要所有的最小计数:

    IEnumerable<BFull> minBFulls = Fulls.GroupBy(x => x.PartsList.Count).OrderBy(g => g.Key).First();
    

    【讨论】:

      猜你喜欢
      • 2012-04-17
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 2013-01-28
      • 2013-06-25
      • 2011-09-20
      • 2011-09-12
      • 2012-12-27
      相关资源
      最近更新 更多