Enumerable.Skip<TSource>(IEnumerable<TSource>, Int32) Yöntem

Tanım

Bir dizideki belirtilen sayıda öğeyi atlar ve kalan öğeleri döndürür.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Collections::Generic::IEnumerable<TSource> ^ Skip(System::Collections::Generic::IEnumerable<TSource> ^ source, int count);
public static System.Collections.Generic.IEnumerable<TSource> Skip<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, int count);
static member Skip : seq<'Source> * int -> seq<'Source>
<Extension()>
Public Function Skip(Of TSource) (source As IEnumerable(Of TSource), count As Integer) As IEnumerable(Of TSource)

Tür Parametreleri

TSource

öğelerinin sourcetürü.

Parametreler

source
IEnumerable<TSource>

IEnumerable<T> Öğesinden öğe döndürülecek.

count
Int32

Kalan öğeleri döndürmeden önce atlana öğelerin sayısı.

Döndürülenler

IEnumerable<TSource>

IEnumerable<T> Giriş dizisinde belirtilen dizinden sonra oluşan öğeleri içeren.

Özel durumlar

source, null'e eşittir.

Örnekler

Aşağıdaki kod örneği, bir dizideki belirtilen sayıda öğeyi atlamak ve kalan öğeleri döndürmek için nasıl kullanılacağını Skip gösterir.

int[] grades = { 59, 82, 70, 56, 92, 98, 85 };

Console.WriteLine("All grades except the first three:");
foreach (int grade in grades.Skip(3))
{
    Console.WriteLine(grade);
}

/*
 This code produces the following output:

All grades except the first three:
 56
 92
 98
 85
*/
' Create an array of integers that represent grades.
Dim grades() As Integer = {59, 82, 70, 56, 92, 98, 85}

' Sort the numbers in descending order and
' get all but the first (largest) three numbers.
Dim skippedGrades As IEnumerable(Of Integer) =
grades _
.Skip(3)

' Display the results.
Dim output As New System.Text.StringBuilder("All grades except the first three are:" & vbCrLf)
For Each grade As Integer In skippedGrades
    output.AppendLine(grade)
Next
Console.WriteLine(output.ToString())

' This code produces the following output:
'
' All grades except the first three are:
' 56
' 92
' 98
' 85

Açıklamalar

Bu yöntem ertelenen yürütme kullanılarak uygulanır. Hemen dönüş değeri, eylemi gerçekleştirmek için gereken tüm bilgileri depolayan bir nesnedir. Bu yöntemle temsil edilen sorgu, nesne doğrudan GetEnumerator yöntemini çağırarak veya C# içinde foreach veya Visual Basic'de For Each kullanılarak numaralandırılana kadar yürütülür.

source Öğeden daha count az öğe içeriyorsa boş IEnumerable<T> bir öğe döndürülür. Sıfırdan küçük veya sıfıra eşitse count , öğesinin source tüm öğeleri oluşturulur.

Take ve Skip yöntemleri işlevsel tamamlayıcılardır. Bir koleksiyon dizisi coll ve bir tamsayı verilip nve sonuçlarını coll.Take(n) birleştirir ve coll.Skip(n) ile collaynı diziyi verir.

Visual Basic sorgu ifadesi söz diziminde Skip yan tümcesi, Skip çağrısına dönüşür.

Şunlara uygulanır

Ayrıca bkz.