To check for duplicates values/objects’ properties between 2 list or the list itself, we use the .Exist() function provided by the List collection type.
//Code in C# List<string> lstListA = new List<string>(); List<string> lstListB = new List<string>(); lstListA.Add("ADuplicate"); lstListA.Add("Some"); lstListA.Add("Some Brown Cow"); lstListA.Add("Some Brown Cow"); lstListB.Add("ADuplicate"); lstListB.Add("This"); lstListB.Add("Don't"); lstListB.Add("Contain"); lstListB.Add("Duplicates"); //Check for duplicates between 2 list foreach(string strValue in lstListA) { if(lstListB.Exists(delegate (string match){ return match.ToLower().Trim() == strValue.ToLower().Trim(); })){ //duplicate found } } //Check for duplicates within the list //Create 2 list, one will hold values with no duplicates and 1 will hold duplicate values found List<string> lstNoDuplicate = new List<string>(); List<string> lstDuplicate = new List<string>(); foreach (string strValue in lstListA) { if (lstNoDuplicate.Exists(delegate(string match) { return match.ToLower().Trim() == strValue.ToLower().Trim(); })) { //duplicate found //we add to duplicate list lstDuplicate.Add(strValue); } else { //no duplicate found //we add to no duplicate list lstNoDuplicate.Add(strValue); } } //lstDuplicate will contain items that are duplicated in lstListA //lstNoDuplicate will contain unique items in lstListA