One way is using Distinct to make your strings unique:
List<string> a = new List<string>();
a.AddRange(new string[] { "a", "b", "a", "c", "d", "b" });
List<string> b = new List<string>();
b.AddRange(a.Distinct());
Another resource on LINQ's Distinct: http://blogs.msdn.com/b/charlie/archive/2006/11/19/linq-farm-group-and-distinct.aspx
Another way: use a HashSet as others suggested;
HashSet<string> hash = new HashSet<string>(inputStrings);
Have a look for this link, to see how to implement it in .net 2.0: https://stackoverflow.com/a/687042/284240
If you're not on 3.5, you also can do it manually:
List<string> newList = new List<string>();
foreach (string s in list)
{
if (!newList.Contains(s))
newList.Add(s);
}
// newList contains the unique values
Another solution (maybe a little faster):
Dictionary<string,bool> dic = new Dictionary<string,bool>();
foreach (string s in list)
{
dic[s] = true;
}
List<string> newList = new List<string>(dic.Keys);
// newList contains the unique values
https://stackoverflow.com/a/1205813/284240