Queryable.LongCount 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.
Sıralı öğe sayısını temsil eden bir Int64 döndürür.
Aşırı Yüklemeler
| Name | Description |
|---|---|
| LongCount<TSource>(IQueryable<TSource>) |
Bir Int64 dizideki öğelerin toplam sayısını temsil eden bir döndürür. |
| LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) |
Bir Int64 koşulu karşılayan bir dizideki öğe sayısını temsil eden bir döndürür. |
LongCount<TSource>(IQueryable<TSource>)
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
Bir Int64 dizideki öğelerin toplam sayısını temsil eden bir döndürür.
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ür Parametreleri
- TSource
öğelerinin sourcetürü.
Parametreler
- source
- IQueryable<TSource>
IQueryable<T> Sayılacak öğeleri içeren.
Döndürülenler
içindeki sourceöğelerin sayısı.
- Öznitelikler
Özel durumlar
source, null'e eşittir.
Öğe sayısı Int64.MaxValue değerini aşıyor.
Örnekler
Aşağıdaki kod örneği, dizideki öğeleri saymak için nasıl kullanılacağını LongCount<TSource>(IQueryable<TSource>) gösterir.
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.
Açıklamalar
yöntemi, LongCount<TSource>(IQueryable<TSource>) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağıran LongCount<TSource>(IQueryable<TSource>) bir oluşturur. Ardından parametresinin özelliği tarafından Provider temsil edilen yöntemine sourceIQueryProvider iletirMethodCallExpression.Execute<TResult>(Expression)
Çağrıyı LongCount<TSource>(IQueryable<TSource>) temsil eden bir ifade ağacının yürütülmesi sonucunda oluşan sorgu davranışı, parametre türünün uygulanmasına source bağlıdır. Beklenen davranış, içindeki source öğe sayısını sayıp bir Int64döndürmesidir.
Şunlara uygulanır
LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
Bir Int64 koşulu karşılayan bir dizideki öğe sayısını temsil eden bir döndürür.
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ür Parametreleri
- TSource
öğelerinin sourcetürü.
Parametreler
- source
- IQueryable<TSource>
IQueryable<T> Sayılacak öğeleri içeren.
- predicate
- Expression<Func<TSource,Boolean>>
Bir koşul için her öğeyi test etmek için bir işlev.
Döndürülenler
koşul işlevindeki source koşulu karşılayan öğelerinin sayısı.
- Öznitelikler
Özel durumlar
source veya predicate şeklindedir null.
Eşleşen öğelerin sayısı Int64.MaxValue değerini aşıyor.
Örnekler
Aşağıdaki kod örneği, bir koşulu karşılayan bir dizideki öğeleri saymak için nasıl kullanılacağını LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) gösterir.
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.
Açıklamalar
Bu yöntem, tür bağımsız değişkeni türlerden Expression<TDelegate> biri olan en az bir tür parametresine Func<T,TResult> sahiptir. Bu parametreler için bir lambda ifadesi geçirebilirsiniz ve bu ifade bir Expression<TDelegate>olarak derlenir.
yöntemi, LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağıran LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) bir oluşturur. Ardından parametresinin özelliği tarafından Provider temsil edilen yöntemine sourceIQueryProvider iletirMethodCallExpression.Execute<TResult>(Expression)
Çağrıyı LongCount<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) temsil eden bir ifade ağacının yürütülmesi sonucunda oluşan sorgu davranışı, parametre türünün uygulanmasına source bağlıdır. Beklenen davranış, tarafından predicate belirtilen koşulu karşılayan öğe source sayısını sayıp bir Int64döndürür.