Q:

C# DataSet - Retrieving Unique Value based on column

I'm having some issues trying to retrieve unique values from a DataSet in csharp, is that possible?
Actually I'm doing something like this that gets a dataset from a webservice:
 webService.getInstructions(Username, Password, AppKey).Tables[0].Select(null, "account name asc");

So in this case I get a alphabetical list from the accounts, but there are some duplicated rows in this dataset.
Is there any way to make this Dataset return values with unique "account number" and sort it alphabetically by "account name"?
Something in place of the filterExpression would be very nice I think. :)
Thanks in advance

A:

Personally I'd change the web-service to do this filtering and sorting at the server to reduce bandwidth needs, probably returning a simple data-type or custom class (not DataTable or anything similar). But LINQ would do the job... (updated after re-reading the question)
var rows = dataset.Tables[0].AsEnumerable()
    .DistinctBy(row => row.Field<string>("account number"))
    .OrderBy(row => row.Field<string>("account name"))
    .ToArray();

using custom DistinctBy method:
    static IEnumerable<TSource> DistinctBy<TSource, TValue>(
        this IEnumerable<TSource> source,
        Func<TSource, TValue> selector)
    {
        HashSet<TValue> unique = new HashSet<TValue>();
        foreach (var item in source)
        {
            if (unique.Add(selector(item))) yield return item;
        }
    }

