1

I have an list of person same as below:

List<Person> Persons=New List<Person>

Person class contains some property such as Id,Firstname,LastName,Age,... in this list exist some repetitive object with same Firstname and LastName

how can i recognize and find repetitive objects Id?

Morteza Nemati
  • 237
  • 3
  • 9

2 Answers2

1

From Eric White's blog:

int[] listOfItems = new[] { 4, 2, 3, 1, 6, 4, 3 };
var duplicates = listOfItems
    .GroupBy(i => i)
    .Where(g => g.Count() > 1)
    .Select(g => g.Key);
foreach (var d in duplicates)
    Console.WriteLine(d);
Jordan Parmer
  • 36,042
  • 30
  • 97
  • 119
0

If I recall correctly, this should create a unique list if this is what you're after:

List<String> list2 = new ArrayList<String>(new HashSet<String>(list1));
Harlin
  • 1,059
  • 14
  • 18