List<SelectListItem> allClientUserAndCandidateViews = new List<SelectListItem>();
foreach (var clientUserView in clientUserViews)
{
SelectListItem item =
new SelectListItem
{
Value = clientUserView.ClientViewId.ToString(),
Text = clientUserView.Name
};
allClientUserAndCandidateViews.Add(item);
}
// First way to return duplicates in a list of SelectListItem objects
foreach (SelectListItem item in allClientUserAndCandidateViews)
{
if (dupeDictionary.ContainsKey(item.Text))
dupes.Add(item);
else
dupeDictionary.Add(item.Text, item);
}
// Second way to return duplicates in a list of SelectListItem objects
List<SelectListItem> matchinClientUserAndCandidateViews = allClientUserAndCandidateViews
.GroupBy(x => new { x.Value, x.Text })
.Where(g => g.Count() > 1)
.Select(y => y.First())
.ToList();