Linq跳过,接 [英] Linq skip, take

查看:85
本文介绍了Linq跳过,接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含4行的列表. 我需要获取第三行的值.

I have a list that has 4 rows. I need to get the value of the 3rd row.

    var result = (from rs in list
                  select rs).Skip(2).First();

我为什么要在此场景中使用Take(1)?

Is there a reason why I would want to use a Take(1) in this scenerio as I have seen used.

     var result = (from rs in list
                  select rs).Skip(2).Take(1);

推荐答案

Take(1)返回包含一个对象的IEnumerable<T>.
First()直接返回对象.

Take(1) returns an IEnumerable<T> containing one object.
First() returns the object directly.

这篇关于Linq跳过,接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆