I have a collection of objects from a database that holds the titles of companies.
I need to get the first letters (char[]) of all the titles distincted (.Distinct()).
Currently I have something like:
public char[] GetBrandsAlphabet()
{
using (var dc = ReturnContext())
{
var resultBrands =
from brands in dc.Brands
orderby brands.Title ascending
select brands.Title.ToCharArray()[0];
char[] ret = new char[resultBrands.Distinct().Count()];
}
}
However, this might not work exactly the way that you want, since
Distinctcould, in principle, change the ordering of the elements. I would remove theorderbystatement from the sql statement and use: