Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- namespace Linq_Set_op_element_op
- {
- class stringComparer : IEqualityComparer<string>
- {
- public bool Equals(string s1, string s2)
- {
- return string.Compare(s1 , s2)==0;
- }
- public int GetHashCode(string obj)
- {
- return obj.GetHashCode();
- }
- }
- class Program
- {
- static void stampa(IEnumerable<string> elenco)
- {
- foreach (string s in elenco) Console.WriteLine(s);
- }
- static void Main(string[] args)
- {
- string[] files1 = Directory.GetFiles(@"g:\tempSuG")
- .Select(path_e_nome => Path.GetFileName(path_e_nome)).ToArray();
- string[] files2 = Directory.GetFiles(@"g:\PresenzeFAD\3B")
- .Select(path_e_nome => Path.GetFileName(path_e_nome)).ToArray();
- var concatenamento = files1.Concat(files1);
- var unione = files1.Union(files2);
- unione = files1.Union(files2);
- //Console.WriteLine( $"{files1.Count()} {files2.Count()} {unione.Count()}");
- var intersezione = files1.Intersect(files2);
- //stampa(intersezione);
- var differenza = files2.Except(files1);
- //stampa(differenza);
- Console.WriteLine(unione.First());
- Console.WriteLine(unione.First(nomeFile => nomeFile.Length>10));
- Console.WriteLine(unione.Last());
- Console.WriteLine(unione.ElementAt(12));
- Console.WriteLine(unione.Min());
- Console.WriteLine(unione.Min(nomeFile => nomeFile.Length));
- Console.WriteLine(unione.Sum(nomeFile => nomeFile.Length));
- Console.WriteLine(unione.Average(nomeFile => nomeFile.Length));
- Console.WriteLine(unione.Any(nomeFile => nomeFile.Length>30));
- Console.WriteLine(unione.All(nomeFile => nomeFile.Length>30));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement