LINQ:如何跳过一个再取一序列的其余部分 [英] LINQ: How to skip one then take the rest of a sequence

查看:616
本文介绍了LINQ:如何跳过一个再取一序列的其余部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想遍历名单,LT的物品; T> ,除了第一,维护秩序。有一种优雅的方式与使用LINQ像一个语句来做到这一点:

i would like to iterate over the items of a List<T>, except the first, preserving the order. Is there an elegant way to do it with LINQ using a statement like:

的foreach(在list.Skip VAR项(1)< STRONG> TakeTheRest())
{....

foreach (var item in list.Skip(1).TakeTheRest()) {....

我打得四处 TakeWhile ,但没有成功。有可能是另一种,这样做的简单的方法

I played around with TakeWhile , but was not successful. Probably there is also another, simple way of doing it?

推荐答案

从的Skip~~V :在

跳过指定数量的。序列中的元素,然后返回剩余的元素

Bypasses a specified number of elements in a sequence and then returns the remaining elements.

所以,你只需要这样的:

So you just need this:

foreach (var item in list.Skip(1))

这篇关于LINQ:如何跳过一个再取一序列的其余部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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