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):操作一个集合,可以有对个对象匹配,单只返回第一个,但是这里返回的是一个集合,而不是单个的概念。

相关文章:

  • 2021-08-07
  • 2019-01-09
  • 2021-10-13
  • 2021-10-23
  • 2021-08-30
  • 2022-01-04
  • 2021-08-27
  • 2021-09-07
猜你喜欢
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2021-08-01
  • 2021-11-18
  • 2021-10-28
  • 2021-05-03
相关资源
相似解决方案