Tuesday, 21 February 2017

C# .NET Get the List of Elements Which are in List1 but not in List2 and Vice Versa

// define the lists
List<string> list1 = new List<string>() { "a", "b", "c", "d", "e", "zz","ZZ" };
List<string> list2 = new List<string>() { "ZZ", "H","b" };

// convert the list elements to lowercase
list1 = list1.Select(x => x.ToLower()).ToList();
list2 = list2.Select(x => x.ToLower()).ToList();

// create desire lists
List<string> ItemsInList1NotInList2 = list1.Except(list2).ToList();
List<string> ItemsInList2NotInList1 = list2.Except(list1).ToList();


No comments:

SQL: Generate a range of numbers

SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n FROM       (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),      (VALU...