[英]Get all elements but the first from an array
Is there a one-line easy linq expression to just get everything from a simple array except the first element?是否有一行简单的 linq 表达式可以从一个简单的数组中获取除第一个元素之外的所有内容?
for (int i = 1; i <= contents.Length - 1; i++)
Message += contents[i];
I just wanted to see if it was easier to condense.我只是想看看它是否更容易凝结。
Yes, Enumerable.Skip does what you want:是的, Enumerable.Skip做你想要的:
contents.Skip(1)
However, the result is an IEnumerable<T>, if you want to get an array use:然而,结果是一个 IEnumerable<T>,如果你想获得一个数组,请使用:
contents.Skip(1).ToArray()
The following would be equivalent to your for
loop:以下内容相当于您的for
循环:
foreach (var item in contents.Skip(1))
Message += item;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.