LINQ: difference between Single(), First(), and Take(1)
2010-02-27 14:04 AnyKoro 阅读(686) 评论(0) 编辑 收藏 举报LINQ provides a few different methods that return you a single object: Single(), First(), and Take(1).It took me a while, but I think I understand the difference: Single() operates on a collection of exactly one object and simply returns the object. First() operates on a collection of any number of objects and returns the first object. Take(1) operates on a collection of any number of objects and returns a collection containing the first object....
Linq提供了一些不同的返回单个对象的函数:Single(),First()和Take(1)。
Single():操作一个集合,同时强要求只有一个对象匹配,并返回这一个。
First():操作一个集合,可以有多个对象匹配,但是只返回第一个。
Take(1):操作一个集合,可以有对个对象匹配,单只返回第一个,但是这里返回的是一个集合,而不是单个的概念。
作者:AnyKoro
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。