Queryable.ElementAt Metódus

Definíció

Túlterhelések

Name Description
ElementAt<TSource>(IQueryable<TSource>, Index)

Egy adott index elemet ad vissza egy sorozatban.

ElementAt<TSource>(IQueryable<TSource>, Int32)

Egy adott index elemet ad vissza egy sorozatban.

ElementAt<TSource>(IQueryable<TSource>, Index)

Forrás:
Queryable.cs
Forrás:
Queryable.cs
Forrás:
Queryable.cs
Forrás:
Queryable.cs
Forrás:
Queryable.cs

Egy adott index elemet ad vissza egy sorozatban.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource ElementAt(System::Linq::IQueryable<TSource> ^ source, Index index);
public static TSource ElementAt<TSource>(this System.Linq.IQueryable<TSource> source, Index index);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static TSource ElementAt<TSource>(this System.Linq.IQueryable<TSource> source, Index index);
static member ElementAt : System.Linq.IQueryable<'Source> * Index -> 'Source
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
static member ElementAt : System.Linq.IQueryable<'Source> * Index -> 'Source
<Extension()>
Public Function ElementAt(Of TSource) (source As IQueryable(Of TSource), index As Index) As TSource

Típusparaméterek

TSource

A . elemeinek sourcetípusa.

Paraméterek

source
IQueryable<TSource>

Egy IQueryable<T> elem visszaadásához.

index
Index

A lekérni kívánt elem indexe, amely az elejétől vagy végétől számít.

Válaszok

TSource

A sorrendben megadott pozícióban lévő source elem.

Attribútumok

Kivételek

source az null.

index kívül esik a source sorozat határain.

A következőre érvényes:

ElementAt<TSource>(IQueryable<TSource>, Int32)

Forrás:
Queryable.cs
Forrás:
Queryable.cs
Forrás:
Queryable.cs
Forrás:
Queryable.cs
Forrás:
Queryable.cs

Egy adott index elemet ad vissza egy sorozatban.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource ElementAt(System::Linq::IQueryable<TSource> ^ source, int index);
public static TSource ElementAt<TSource>(this System.Linq.IQueryable<TSource> source, int index);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static TSource ElementAt<TSource>(this System.Linq.IQueryable<TSource> source, int index);
static member ElementAt : System.Linq.IQueryable<'Source> * int -> 'Source
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
static member ElementAt : System.Linq.IQueryable<'Source> * int -> 'Source
<Extension()>
Public Function ElementAt(Of TSource) (source As IQueryable(Of TSource), index As Integer) As TSource

Típusparaméterek

TSource

A . elemeinek sourcetípusa.

Paraméterek

source
IQueryable<TSource>

Egy IQueryable<T> elem visszaadásához.

index
Int32

A lekérni kívánt elem nulla alapú indexe.

Válaszok

TSource

A megadott pozícióban lévő elem a következőben source: .

Attribútumok

Kivételek

source az null.

index kisebb, mint nulla.

Példák

Az alábbi példakód bemutatja, hogyan lehet ElementAt<TSource>(IQueryable<TSource>, Int32) visszaadni egy elemet egy adott pozícióban egy sorozatban.

string[] names = { "Hartono, Tommy", "Adams, Terry",
                   "Andersen, Henriette Thaulow",
                   "Hedlund, Magnus", "Ito, Shu" };

Random random = new Random(DateTime.Now.Millisecond);

string name =
    names.AsQueryable().ElementAt(random.Next(0, names.Length));

Console.WriteLine("The name chosen at random is '{0}'.", name);

/*
    This code produces the following sample output.
    Yours may be different due to the use of Random.

    The name chosen at random is 'Ito, Shu'.
*/
Dim names() As String = {"Hartono, Tommy", "Adams, Terry", _
                   "Andersen, Henriette Thaulow", _
                   "Hedlund, Magnus", "Ito, Shu"}

Dim rand As New Random(DateTime.Now.Millisecond)

Dim name As String = _
    names.AsQueryable().ElementAt(rand.Next(0, names.Length))

MsgBox(String.Format("The name chosen at random is '{0}'.", name))

' This code produces the following sample output.
' Yours may be different due to the use of Random.
'
' The name chosen at random is 'Ito, Shu'.

Megjegyzések

A ElementAt<TSource>(IQueryable<TSource>, Int32) metódus létrehoz egy olyan metódust MethodCallExpression , amely önmagát generált általános metódusként jeleníti ElementAt<TSource>(IQueryable<TSource>, Int32) meg. Ezután átadja a MethodCallExpression paraméter tulajdonsága által Execute<TResult>(Expression) képviselt metódusnak IQueryProviderProvider.source

A meghívást ElementAt<TSource>(IQueryable<TSource>, Int32) jelképező kifejezésfa végrehajtása során előforduló lekérdezési viselkedés a paraméter típusának source implementálásától függ. A várt viselkedés az, hogy az elemet a következő pozícióban indexsourceadja vissza: .

A következőre érvényes: