fcamuso

Linq E

Dec 3rd, 2021
739
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6.  
  7. namespace Linq_Set_op_element_op
  8. {
  9.   class stringComparer : IEqualityComparer<string>
  10.   {
  11.     public bool Equals(string s1, string s2)
  12.     {
  13.       return string.Compare(s1 , s2)==0;
  14.     }
  15.  
  16.     public int GetHashCode(string obj)
  17.     {
  18.       return obj.GetHashCode();
  19.     }
  20.   }
  21.  
  22.   class Program
  23.   {
  24.     static void stampa(IEnumerable<string> elenco)
  25.     {
  26.       foreach (string s in elenco) Console.WriteLine(s);
  27.     }
  28.    
  29.  
  30.     static void Main(string[] args)
  31.     {
  32.       string[] files1 = Directory.GetFiles(@"g:\tempSuG")
  33.                         .Select(path_e_nome => Path.GetFileName(path_e_nome)).ToArray();
  34.       string[] files2 = Directory.GetFiles(@"g:\PresenzeFAD\3B")
  35.                         .Select(path_e_nome => Path.GetFileName(path_e_nome)).ToArray();
  36.  
  37.       var concatenamento = files1.Concat(files1);
  38.       var unione = files1.Union(files2);
  39.  
  40.  
  41.       unione = files1.Union(files2);
  42.       //Console.WriteLine( $"{files1.Count()} {files2.Count()}  {unione.Count()}");
  43.  
  44.       var intersezione = files1.Intersect(files2);
  45.       //stampa(intersezione);
  46.  
  47.       var differenza = files2.Except(files1);
  48.       //stampa(differenza);
  49.  
  50.       Console.WriteLine(unione.First());
  51.       Console.WriteLine(unione.First(nomeFile => nomeFile.Length>10));
  52.  
  53.       Console.WriteLine(unione.Last());
  54.       Console.WriteLine(unione.ElementAt(12));
  55.       Console.WriteLine(unione.Min());
  56.       Console.WriteLine(unione.Min(nomeFile => nomeFile.Length));
  57.       Console.WriteLine(unione.Sum(nomeFile => nomeFile.Length));
  58.       Console.WriteLine(unione.Average(nomeFile => nomeFile.Length));
  59.       Console.WriteLine(unione.Any(nomeFile => nomeFile.Length>30));
  60.       Console.WriteLine(unione.All(nomeFile => nomeFile.Length>30));
  61.  
  62.     }
  63.   }
  64. }
  65.  
RAW Paste Data