Queryable.LongCount Queryable.LongCount Queryable.LongCount Queryable.LongCount Method

定義

返します、Int64シーケンス内の要素の数を表します。Returns an Int64 that represents the number of elements in sequence.

オーバーロード

LongCount<TSource>(IQueryable<TSource>) LongCount<TSource>(IQueryable<TSource>) LongCount<TSource>(IQueryable<TSource>) LongCount<TSource>(IQueryable<TSource>)

返します、Int64シーケンス内の要素の合計数を表します。Returns an Int64 that represents the total number of elements in a sequence.

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

返します、Int64条件を満たす、シーケンス内の要素の数を表します。Returns an Int64 that represents the number of elements in a sequence that satisfy a condition.

LongCount<TSource>(IQueryable<TSource>) LongCount<TSource>(IQueryable<TSource>) LongCount<TSource>(IQueryable<TSource>) LongCount<TSource>(IQueryable<TSource>)

返します、Int64シーケンス内の要素の合計数を表します。Returns an Int64 that represents the total number of elements in a sequence.

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);
static member LongCount : System.Linq.IQueryable<'Source> -> int64
<Extension()>
Public Function LongCount(Of TSource) (source As IQueryable(Of TSource)) As Long

型パラメーター

TSource

source の要素の型。The type of the elements of source.

パラメーター

source
IQueryable<TSource>

IQueryable<T>カウントする要素を格納しています。An IQueryable<T> that contains the elements to be counted.

戻り値

source にある要素の数。The number of elements in source.

例外

要素の数を超えるMaxValueします。The number of elements exceeds MaxValue.

次のコード例は、使用する方法を示しますLongCount<TSource>(IQueryable<TSource>)配列の要素をカウントします。The following code example demonstrates how to use LongCount<TSource>(IQueryable<TSource>) to count the elements in an array.

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.

注釈

LongCount<TSource>(IQueryable<TSource>)メソッドを生成、MethodCallExpression呼び出しを表すLongCount<TSource>(IQueryable<TSource>)として構築されたジェネリック メソッド自体。The LongCount<TSource>(IQueryable<TSource>) method generates a MethodCallExpression that represents calling LongCount<TSource>(IQueryable<TSource>) itself as a constructed generic method. これは、後、渡します、MethodCallExpressionExecute<TResult>(Expression)のメソッド、IQueryProviderによって表される、Providerのプロパティ、sourceパラメーター。It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

呼び出し元を表す式ツリーを実行した結果として発生するクエリの動作LongCount<TSource>(IQueryable<TSource>)の型の実装によって異なります、sourceパラメーター。The query behavior that occurs as a result of executing an expression tree that represents calling LongCount<TSource>(IQueryable<TSource>) depends on the implementation of the type of the source parameter. 想定される動作は内の項目の数をカウントsourceを返します、Int64します。The expected behavior is that it counts the number of items in source and returns an Int64.

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

返します、Int64条件を満たす、シーケンス内の要素の数を表します。Returns an Int64 that represents the number of elements in a sequence that satisfy a condition.

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);
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

型パラメーター

TSource

source の要素の型。The type of the elements of source.

パラメーター

source
IQueryable<TSource>

IQueryable<T>カウントする要素を格納しています。An IQueryable<T> that contains the elements to be counted.

predicate
Expression<Func<TSource,Boolean>>

各要素が条件を満たしているかどうかをテストする関数。A function to test each element for a condition.

戻り値

要素数source述語関数の条件を満たします。The number of elements in source that satisfy the condition in the predicate function.

例外

source または predicatenull です。source or predicate is null.

一致する要素の数を超えるMaxValueします。The number of matching elements exceeds MaxValue.

次のコード例は、使用する方法を示しますLongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)条件を満たす配列内の要素をカウントします。The following code example demonstrates how to use LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) to count the elements in an array that satisfy a condition.

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.

注釈

このメソッドは、少なくとも 1 つのパラメーター型のExpression<TDelegate>型引数は、のいずれか、Func<T,TResult>型。This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. ラムダ式で、これらのパラメーターを渡すことができますにコンパイルされると、Expression<TDelegate>します。For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.

LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)メソッドを生成、MethodCallExpression呼び出しを表すLongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)として構築されたジェネリック メソッド自体。The LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) method generates a MethodCallExpression that represents calling LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) itself as a constructed generic method. これは、後、渡します、MethodCallExpressionExecute<TResult>(Expression)のメソッド、IQueryProviderによって表される、Providerのプロパティ、sourceパラメーター。It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

呼び出し元を表す式ツリーを実行した結果として発生するクエリの動作LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)の型の実装によって異なります、sourceパラメーター。The query behavior that occurs as a result of executing an expression tree that represents calling LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) depends on the implementation of the type of the source parameter. 想定される動作は内の項目の数をカウントsourceで指定された条件を満たすpredicateを返します、Int64します。The expected behavior is that it counts the number of items in source that satisfy the condition specified by predicate and returns an Int64.

適用対象