Sunday 18 June 2023

Remove items from one list in another in C#

List<string> list1 = new List<string>() { "A", "B", "C", "D" };
List<string> list2 = new List<string>() { "B", "D" }; 
List<string> list3 = list1.Except(list2).ToList();

Here, in the list3 object, we will get the value A & C.

No comments:

Post a Comment