如何实现的LINQ排序依据的方法? [英] How to implement Linq OrderBy method?
本文介绍了如何实现的LINQ排序依据的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更多地了解LINQ的,例如,如果我想实现一个选择,我会实现这样的
I am trying to understand more about linq, for example, if I want to implement a Select I will implement like this
public static IEnumerable<TResult> Select<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, TResult> selector)
{
foreach (var item in source)
{
yield return selector(item);
}
}
在哪里这样的。
where like this
public static IEnumerable<TSource> Where<TSource>(IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
foreach (var item in source)
{
if (predicate(item))
yield return item;
}
}
如何排序依据?
How about OrderBy?
推荐答案
看看的这个。我想你会发现它非常有用。基本上,乔恩斯基特重新实现了LINQ的一切作为一个学习锻炼。内容非常丰富。
Take a look at this. I think you'll find it very useful. Basically, Jon Skeet re-implements everything in Linq as a learning exercise. Very informative.
The second part talks about implementing where... and so on till parts that describes OrderBy.
这篇关于如何实现的LINQ排序依据的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文