I have a bunch of string data and I can loop through it one by one. What’s a good collection (and how to implement it) so that I only get the distinct strings?
The client I am doing this for doesn’t even use .NET 3.5 so .Distinct is out. They use .NET framework 2.0.
And I am reading the list one at a time and don’t know how many records it will have until I’m done.
One way is using Distinct to make your strings unique:
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;
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:
Another solution (maybe a little faster):
https://stackoverflow.com/a/1205813/284240