If you are using .NET 3.5, try the following:
List<string> categories = collection
.Cast<Foo>()
.Select(foo => foo.Category)
.Distinct()
.ToList();
It should be very fast.
I assume that these objects were originally obtained from the database? If so, you can ask the database to do the work for you. If there is an index in this column, you will immediately get the result immediately, without even bringing the objects into memory.
source
share