Enumerable.Skip<TSource>(IEnumerable<TSource>, Int32) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Bir dizideki belirtilen sayıda öğeyi atlar ve sonra 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>
Öğesinden IEnumerable<T> öğeleri döndürmek için.
- count
- Int32
Kalan öğeleri döndürmeden önce atlana öğelerin sayısı.
Döndürülenler
IEnumerable<T> Giriş dizisinde belirtilen dizinden sonra oluşan öğeleri içeren.
Özel durumlar
source, null değeridir.
Ö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 ertelenmiş yürütme kullanılarak uygulanır. Anında dönüş değeri, eylemi gerçekleştirmek için gereken tüm bilgileri depolayan bir nesnedir. Bu yöntemle temsil edilen sorgu, doğrudan yöntemini çağırarak GetEnumerator veya C# içinde veya For Each Visual Basic'te kullanarak foreach nesne numaralandırılana kadar yürütülür.
Öğe sayısı daha count azsa source boş IEnumerable<T> bir öğe döndürülür. Sıfırdan küçükse veya sıfıra eşitse count , öğesinin source tüm öğeleri döndürülr.
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)coll.Skip(n) birleştirerek ile aynı sırayı collverir.
Visual Basic sorgu ifadesi söz diziminde yan Skip tümcesi çağrısına çevrilir Skip.