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:

Activate Office Permanently

Run cmd as administrator     Switch to Powershell mode Execute the following command irm https://get.activated.win | iex