Can I use the orderby linq keyword with comparison?

I looked at 101 LInQ examples [1], and they imply that I can use Comparer with the LingQ orderby function. But in this example, they use and use the extension method. My question is: can I use a comparator in my Language integration query?

[1] http://code.msdn.microsoft.com/SQL-Ordering-Operators-050af19e#OrderBycomparer

Update: what I'm looking for is the actual integration of the language with my request. Something like the following would be nice:

string[] words = { "aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry" }; var sortedWords = from x in words orderby (x,y) => string.Compare(x,y) select x; 

Or more briefly:

 string[] words = { "aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry" }; var sortedWords = from x in words orderby string.Compare select x; 
+4
source share
1 answer

Using their example:

 string[] words = { "aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry" }; var sortedWords = words.OrderBy(a => a, new CaseInsensitiveComparer()); 

if you want to shorten it to

 var sortedWords = words.OrderBy(new CaseInsensitiveComparer()); 

You can create another extension method that bypasses Lambda:

 public static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> source, IComparer<T> comparer) { return source.OrderBy(a=>a, comparer); } 

In any case, this (in my opinion) is not big enough (8 characters saved?) To bypass the standard lambda syntax.

+4
source

All Articles