किसी सरणी में तत्वों की संख्या को छोड़ने के लिए C# में स्किप () विधि का उपयोग करें।
मान लें कि निम्नलिखित हमारी सरणी है -
int[] arr = { 10, 20, 30, 40, 50 }; पहले दो तत्वों को छोड़ने के लिए, छोड़ें () विधि का उपयोग करें और तर्क को 2 के रूप में जोड़ें -
arr.Skip(2);
आइए एक उदाहरण देखें -
उदाहरण
using System.IO;
using System;
using System.Linq;
public class Demo {
public static void Main() {
int[] arr = { 10, 20, 30, 40, 50 };
Console.WriteLine("Initial Array...");
foreach (var res in arr) {
Console.WriteLine(res);
}
// skipping first two elements
var ele = arr.Skip(2);
Console.WriteLine("New Array after skipping elements...");
foreach (var res in ele) {
Console.WriteLine(res);
}
}
} आउटपुट
Initial Array... 10 20 30 40 50 New Array after skipping elements... 30 40 50