【问题标题】:Retrieving all values from IGrouping从 IGrouping 检索所有值
【发布时间】:2012-08-01 19:16:33
【问题描述】:

我目前有:

UIEnumerable <IGrouping<PortableKey, FileInfo>> 

从此代码:

var queryDupFiles = from file in fileList
    group file by new PortableKey { Name = file.Name, Length = file.Length } 
    into g
    where g.Count() > 1
    select g;

PortableKey 的代码在哪里:

    public class PortableKey
    {
        public string Name { get; set; }
        public long Length { get; set; }
    }

基本上过滤和抓取所有重复的文件。如何获取它以便我以这种方式拥有所有 FileInfo?

List<FileInfo> list

【问题讨论】:

    标签: c# linq list fileinfo igrouping


    【解决方案1】:

    您需要使用额外的from 子句:

    from f in g
    select f
    

    这翻译成.GroupBy(...).SelectMany(g =&gt; g)

    【讨论】:

      猜你喜欢
      • 2011-10-09
      • 1970-01-01
      • 2012-01-21
      • 1970-01-01
      • 2018-07-22
      • 1970-01-01
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多