배열의 여러 요소를 건너뛰려면 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("Initial Array...");
foreach (var res in arr) {
Console.WriteLine(res);
}
// skipping first four elements
var ele = arr.Skip(4);
Console.WriteLine("New Array after skipping elements...");
foreach (var res in ele) {
Console.WriteLine(res);
}
}
} 출력
Initial Array... 24 40 55 62 70 82 89 93 98 New Array after skipping elements... 70 82 89 93 98