keySelector takes keySelector as the first argument. This keySelector should be Func<string,T> . So you need a method that takes a string and returns the value with which to enumerate the enumeration.
Unfortunately, I'm not sure how to determine if a character is an accented letter. RemoveDiacritics does not work for my é .
So, suppose you have a method called IsAccentedLetter that determines if a character is an accented letter:
public bool IsAccentedLetter(char c) {
So, you can sort your list as follows:
string[] myStrings = getStrings(); // whereever your strings come from var ordered = myStrings.OrderBy(s => new string(s.Select(c => IsAccentedLetter(c) ? ' ' : c).ToArray()), StringComparer.Create(culture, false));
The lambda expression takes a string and returns the same string, but replaces the accented letters with empty space. OrderBy now sorts your enumeration with these lines and therefore “ignores” accented letters.
UPDATE: If you have a working RemoveDiacritics(string s) method that returns strings with replaced letters with an accent, you can simply call OrderBy as follows:
string[] mystrings = getStrings(); var ordered = myStrings.OrderBy(RemoveDiacritics, StringComparer.Create(culture, false));
René vogt
source share