Hope someone can help me. I am using c# and I am somewhat new to it.
I am loading a text file into my app and splitting the data on \",\" I am reading part of string into a
A simple/dirty example follows:
public List<string> RemoveDuplicates(List<string> listWithDups)
{
cleanList = new List<string>();
foreach (string s in listWithDups)
{
if (!cleanList.Contains(s))
cleanList.Add(s);
}
return cleanList;
}
As a warning: String.Split on very large strings can cause consume huge amounts of memory and cause exceptions.
Here's an article with some examples and explanations in C#. Basically, you just keep track of the uniques, and check each element.
Alex
If you are targeting .NET 3.5, use the Distinct extension method:
var deduplicated = list.Distinct();
If you load the strings into a Set
instead of into a List
then duplicates are discarded automatically.