Queryable.LongCount Metódus

Definíció

Olyan értéket Int64 ad vissza, amely a sorrendben lévő elemek számát jelöli.

Túlterhelések

Name Description
LongCount<TSource>(IQueryable<TSource>)

Olyan értéket Int64 ad vissza, amely egy sorozat elemeinek teljes számát jelöli.

LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

Olyan értéket Int64 ad vissza, amely egy feltételnek megfelelő sorozat elemeinek számát jelöli.

LongCount<TSource>(IQueryable<TSource>)

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

Olyan értéket Int64 ad vissza, amely egy sorozat elemeinek teljes számát jelöli.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static long LongCount(System::Linq::IQueryable<TSource> ^ source);
public static long LongCount<TSource>(this System.Linq.IQueryable<TSource> 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.")]
public static long LongCount<TSource>(this System.Linq.IQueryable<TSource> source);
static member LongCount : System.Linq.IQueryable<'Source> -> int64
[<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 LongCount : System.Linq.IQueryable<'Source> -> int64
<Extension()>
Public Function LongCount(Of TSource) (source As IQueryable(Of TSource)) As Long

Típusparaméterek

TSource

A . elemeinek sourcetípusa.

Paraméterek

source
IQueryable<TSource>

A IQueryable<T> megszámlálandó elemeket tartalmazó elem.

Válaszok

Az elemek száma a következőben source: .

Attribútumok

Kivételek

source az null.

Az elemek száma meghaladja az Int64.MaxValue értéket.

Példák

Az alábbi példakód bemutatja, hogyan használható LongCount<TSource>(IQueryable<TSource>) a tömb elemeinek megszámlálására.

string[] fruits = { "apple", "banana", "mango",
                      "orange", "passionfruit", "grape" };

long count = fruits.AsQueryable().LongCount();

Console.WriteLine("There are {0} fruits in the collection.", count);

/*
    This code produces the following output:

    There are 6 fruits in the collection.
*/
Dim fruits() As String = {"apple", "banana", "mango", _
                      "orange", "passionfruit", "grape"}

Dim count As Long = fruits.AsQueryable().LongCount()

MsgBox(String.Format("There are {0} fruits in the collection.", count))

' This code produces the following output:

' There are 6 fruits in the collection.

Megjegyzések

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

A meghívást LongCount<TSource>(IQueryable<TSource>) 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 megszámolja a benne lévő source elemek számát, és visszaad egy Int64.

A következőre érvényes:

LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

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

Olyan értéket Int64 ad vissza, amely egy feltételnek megfelelő sorozat elemeinek számát jelöli.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static long LongCount(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, bool> ^> ^ predicate);
public static long LongCount<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,bool>> predicate);
[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 long LongCount<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,bool>> predicate);
static member LongCount : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, bool>> -> int64
[<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 LongCount : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, bool>> -> int64
<Extension()>
Public Function LongCount(Of TSource) (source As IQueryable(Of TSource), predicate As Expression(Of Func(Of TSource, Boolean))) As Long

Típusparaméterek

TSource

A . elemeinek sourcetípusa.

Paraméterek

source
IQueryable<TSource>

A IQueryable<T> megszámlálandó elemeket tartalmazó elem.

predicate
Expression<Func<TSource,Boolean>>

Egy feltétel egyes elemeinek tesztelésére szolgáló függvény.

Válaszok

Azoknak az elemeknek source a száma, amelyek megfelelnek a predikátumfüggvény feltételének.

Attribútumok

Kivételek

source vagy predicate az null.

Az egyező elemek száma meghaladja az Int64.MaxValue értéket.

Példák

Az alábbi példakód bemutatja, hogyan használható LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) egy feltételnek megfelelő tömb elemeinek megszámlálására.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void LongCountEx2()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    const int Age = 3;

    // Count the number of Pet objects where Pet.Age is greater than 3.
    long count = pets.AsQueryable().LongCount(pet => pet.Age > Age);

    Console.WriteLine("There are {0} animals over age {1}.", count, Age);
}

/*
    This code produces the following output:

    There are 2 animals over age 3.
*/
Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Shared Sub LongCountEx2()
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8}, _
                       New Pet With {.Name = "Boots", .Age = 4}, _
                       New Pet With {.Name = "Whiskers", .Age = 1}}

    Const Age As Integer = 3

    ' Count the number of Pet objects where Pet.Age is greater than 3.
    Dim count As Long = pets.AsQueryable().LongCount(Function(Pet) Pet.Age > Age)

    MsgBox(String.Format("There are {0} animals over age {1}.", count, Age))
End Sub

' This code produces the following output:

' There are 2 animals over age 3.

Megjegyzések

Ez a metódus legalább egy típusparamétert Expression<TDelegate> használ, amelynek típusargumentuma az Func<T,TResult> egyik típus. Ezekhez a paraméterekhez átadhat egy lambda kifejezést, és az Expression<TDelegate>egy .

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

A meghívást LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) 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 megszámolja azoknak az elemeknek source a számát, amelyek megfelelnek a megadott predicate feltételnek, és visszaad egy Int64.

A következőre érvényes: