Get all elements but the first from an array

前端 未结 2 701
小鲜肉
小鲜肉 2020-12-08 18:01

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+         


        
相关标签:
2条回答
  • 2020-12-08 18:35

    The following would be equivalent to your for loop:

    foreach (var item in contents.Skip(1))
        Message += item;
    
    0 讨论(0)
  • 2020-12-08 18:50

    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()
    
    0 讨论(0)
提交回复
热议问题