Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear elements in a List<> which are similar to each other in c#

Tags:

arrays

c#

list

I have a list but in this list there are lots of elements which have the same value. I want to clear values which have same value and have one of each element group.

like image 808
Aykut Celik Avatar asked Feb 22 '23 10:02

Aykut Celik


1 Answers

If you are using 3.5+ you can use Linq to accomplish that:

myDistinctList = myList.Distinct();

This assumes that the list value is a primitive or an object that implements IComparable.

like image 90
Joel Etherton Avatar answered May 10 '23 09:05

Joel Etherton