As an aside, if your byte arrays were guaranteed to be the same length, as an alternative you can dynamically create the order by clause, sorting by the first element, then the second, etc, etc, like so:static IEnumerable<foo> OrderBySortField(this IEnumerable<foo> items, int sortLength){ // Validate parameters. if (items == null) throw new ArgumentNullException("items"); if (sortLength < 0) throw new ArgumentOutOfRangeException("sortLength", sortLength, "The sortLength parameter must be a non-negative value."); // Shortcut, if sortLength is zero, return the sequence, as-is. if (sortLength == 0) return items; // The ordered enumerable. IOrderedEnumerable<foo> ordered = items.OrderBy(i => i.sort[0]); // Cycle from the second index on. for (int index = 1; index < sortLength; index++) { // Copy the index. int indexCopy = index; // Sort by the next item in the array. ordered = ordered.ThenBy(i => i.sort[indexCopy]); } // Return the ordered enumerable. return ordered;}然后您可以简单地这样称呼它:And then you can simply call it like so:// You have to supply the length of the array you're sorting on.List<foo> sortedFoo = FooSource(). OrderBySortField(sortLength).ToList(); 这篇关于Linq OrderBy(Byte [])值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-14 04:21