得到一个数组的所有元素,但第一 [英] Get all elements but the first from an array
本文介绍了得到一个数组的所有元素,但第一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有单行容易LINQ表达式只得到一切从一个简单的数组,除了第一个元素?
的(INT I = 1; I< = contents.Length - 1;我++)
+留言内容= [I]
我只是想看看它是否更容易凝结。
< DIV CLASS =h2_lin>解决方案
是的, Enumerable.Skip 你想要做什么:
contents.Skip(1)
然而,结果是一个IEnumerable< T>,如果你想获得一个阵列中使用:
contents.Skip(1).ToArray()
Is there a one-line easy linq expression to just get everything from a simple array except the first element?
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:
contents.Skip(1)
However, the result is an IEnumerable<T>, if you want to get an array use:
contents.Skip(1).ToArray()
这篇关于得到一个数组的所有元素,但第一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文