i used this code:
List<string> lists=new List<string>("apple","orange","banana","apple","mang0","orange");
string names;
names=lists.Distinct()
is that correct?
i used this code:
List<string> lists=new List<string>("apple","orange","banana","apple","mang0","orange");
string names;
names=lists.Distinct()
is that correct?
No, the variable names
has to be a collection. The Distinct
method returns an enumerator, so you probably want to enumerate the result and realise it as a list:
List<string> names = lists.Distinct().ToList();
You can sort the list, then check two and two:
list.Sort();
Int32 index = 0;
while (index < list.Count - 1)
{
if (list[index] == list[index + 1])
list.RemoveAt(index);
else
index++;
}