OrderByDescending - Comparer

Query
public void Linq34()
{
string[] words = { "aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry" };

var sortedWords = words.OrderByDescending(a => a, new CaseInsensitiveComparer());

ObjectDumper.Write(sortedWords);
}
Lambda Expression
public void Linq34()
{
string[] words = { "aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry" };

var sortedWords = words.OrderByDescending(a => a, new CaseInsensitiveComparer());

ObjectDumper.Write(sortedWords);
}
Utility Method
public class CaseInsensitiveComparer : IComparer
{
public int Compare(string x, string y)
{
return string.Compare(x, y, StringComparison.OrdinalIgnoreCase);
}
}
Output
ClOvEr
cHeRry
bRaNcH
BlUeBeRrY
aPPLE
AbAcUs
Related Tutorial
12. Reverse
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 # # # # #