当前位置:
首页 >
Linq中的Where与SkipWhile
发布时间:2025/3/20
36
豆豆
生活随笔
收集整理的这篇文章主要介绍了
Linq中的Where与SkipWhile
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
本文将介绍Linq中的Where与SkipWhile的用法,有时我们容易混淆它们。下面来看一个简单的UnitTest:
SkipWhile只是匹配一开始满足条件的元素。上面的代码一看就明白。更加请参照MSDN
SkipWhile是这样的实现的:
public static IEnumerable<TSource> SkipWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {if (source == null) throw Error.ArgumentNull("source");if (predicate == null) throw Error.ArgumentNull("predicate");return SkipWhileIterator<TSource>(source, predicate); }private static IEnumerable<TSource> SkipWhileIterator<TSource>(IEnumerable<TSource> source, Func<TSource, bool> predicate) {bool iteratorVariable0 = false;foreach (TSource iteratorVariable1 in source){if (!iteratorVariable0 && !predicate(iteratorVariable1)) iteratorVariable0 = true;if (iteratorVariable0){yield return iteratorVariable1;}} }
希望对您开发有帮助。
作者:Petter Liu
出处:http://www.cnblogs.com/wintersun/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
该文章也同时发布在我的独立博客中-Petter Liu Blog。
总结
以上是生活随笔为你收集整理的Linq中的Where与SkipWhile的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 【Visual C++】游戏开发笔记二十
- 下一篇: define 函数定义注意