Advertisement
fcamuso

Linq D

Nov 28th, 2021
991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4.  
  5. namespace Linq_group_setOperation
  6. {
  7.   class Program
  8.   {
  9.     static void Main(string[] args)
  10.     {
  11.       string[] files = Directory.GetFiles(@"g:\tempSuG");
  12.       var elencoRaggruppato = files
  13.         .GroupBy(file => Path.GetExtension(file), file => file.ToUpper())
  14.         .Where(item => item.Count()>10);
  15.      
  16.       foreach (var gruppoEstensione in elencoRaggruppato.OrderBy(gruppo => gruppo.Count())
  17.         )
  18.       {
  19.         Console.Write($"{gruppoEstensione.Key.ToUpper()}: ");
  20.  
  21.         foreach (string nomeFile in gruppoEstensione) Console.WriteLine(nomeFile);
  22.         Console.WriteLine(new string('-', 70));
  23.       }
  24.  
  25.       foreach (var gruppoEstensione in elencoRaggruppato.OrderBy(gruppo => gruppo.Count()))
  26.       {
  27.         Console.Write($"{gruppoEstensione.Key.ToUpper()}: ");
  28.         Console.WriteLine(gruppoEstensione.Count());
  29.       }
  30.     }
  31.   }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement