C# 程序跳过数组中的初始元素

csharpprogrammingserver side programming更新于 2025/9/16 17:08:00

如果要跳过数组中的多个元素,请使用 C# 中的 Skip() 方法。

假设以下是我们的数组 −

int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 };

现在跳过前四个元素 −

var ele = arr.Skip(4);

让我们看看完整的示例 −

示例

using System.IO;
using System;
using System.Linq;
public class Demo {
   public static void Main() {
      int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 };
      Console.WriteLine("初始数组...");
      foreach (var res in arr) {
         Console.WriteLine(res);
      }
      // 跳过前四个元素
      var ele = arr.Skip(4);
      Console.WriteLine("跳过元素后的新数组...");
      foreach (var res in ele) {
         Console.WriteLine(res);
      }
   }
}

输出

初始数组...
24
40
55
62
70
82
89
93
98
跳过元素后的新数组...
70
82
89
93
98

相关文章