Queryable.TakeWhile Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Egy sorozat elemeit adja vissza mindaddig, amíg egy megadott feltétel igaz, majd kihagyja a fennmaradó elemeket.
Túlterhelések
| Name | Description |
|---|---|
| TakeWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) |
Egy sorozat elemeit adja vissza mindaddig, amíg egy megadott feltétel igaz. |
| TakeWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) |
Egy sorozat elemeit adja vissza mindaddig, amíg egy megadott feltétel igaz. Az elem indexe a predikátumfüggvény logikájában használatos. |
TakeWhile<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
Egy sorozat elemeit adja vissza mindaddig, amíg egy megadott feltétel igaz.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static System::Linq::IQueryable<TSource> ^ TakeWhile(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, bool> ^> ^ predicate);
public static System.Linq.IQueryable<TSource> TakeWhile<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 System.Linq.IQueryable<TSource> TakeWhile<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,bool>> predicate);
static member TakeWhile : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, bool>> -> System.Linq.IQueryable<'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 TakeWhile : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, bool>> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function TakeWhile(Of TSource) (source As IQueryable(Of TSource), predicate As Expression(Of Func(Of TSource, Boolean))) As IQueryable(Of TSource)
Típusparaméterek
- TSource
A . elemeinek sourcetípusa.
Paraméterek
- source
- IQueryable<TSource>
A sorozat, amelyből elemeket ad vissza.
- predicate
- Expression<Func<TSource,Boolean>>
Egy feltétel egyes elemeinek tesztelésére szolgáló függvény.
Válaszok
Olyan IQueryable<T> elem, amely a bemeneti sorozat elemeit tartalmazza, mielőtt az elem, amelyen a megadott predicate teszt már nem halad át.
- Attribútumok
Kivételek
source vagy predicate az null.
Példák
Az alábbi példakód bemutatja, hogyan lehet TakeWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) elemeket visszaadni egy sorozat kezdetétől, amíg egy feltétel igaz.
string[] fruits = { "apple", "banana", "mango", "orange",
"passionfruit", "grape" };
// Take strings from the array until a string
// that is equal to "orange" is found.
IEnumerable<string> query =
fruits.AsQueryable()
.TakeWhile(fruit => String.Compare("orange", fruit, true) != 0);
foreach (string fruit in query)
Console.WriteLine(fruit);
/*
This code produces the following output:
apple
banana
mango
*/
Dim fruits() As String = {"apple", "banana", "mango", "orange", _
"passionfruit", "grape"}
' Take strings from the array until a string
' that is equal to "orange" is found.
Dim query = fruits.AsQueryable() _
.TakeWhile(Function(fruit) String.Compare("orange", fruit, True) <> 0)
Dim output As New System.Text.StringBuilder
For Each fruit As String In query
output.AppendLine(fruit)
Next
' Display the output.
MsgBox(output.ToString())
'This code produces the following output:
'apple
'banana
'mango
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 TakeWhile<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 TakeWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>) meg. Ezután átadja a MethodCallExpression paraméter tulajdonsága által CreateQuery(Expression) képviselt metódusnak IQueryProviderProvider.source
A meghívást TakeWhile<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 az egyes elemekre predicate vonatkoziksource, amíg meg nem talál egy olyan elemet, amelynek predicate a visszaadása falsemegtörténik. Az összes elemet visszaadja addig a pontig.
A következőre érvényes:
TakeWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>)
- Forrás:
- Queryable.cs
- Forrás:
- Queryable.cs
- Forrás:
- Queryable.cs
- Forrás:
- Queryable.cs
- Forrás:
- Queryable.cs
Egy sorozat elemeit adja vissza mindaddig, amíg egy megadott feltétel igaz. Az elem indexe a predikátumfüggvény logikájában használatos.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static System::Linq::IQueryable<TSource> ^ TakeWhile(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, int, bool> ^> ^ predicate);
public static System.Linq.IQueryable<TSource> TakeWhile<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,int,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 System.Linq.IQueryable<TSource> TakeWhile<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,int,bool>> predicate);
static member TakeWhile : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, int, bool>> -> System.Linq.IQueryable<'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 TakeWhile : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, int, bool>> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function TakeWhile(Of TSource) (source As IQueryable(Of TSource), predicate As Expression(Of Func(Of TSource, Integer, Boolean))) As IQueryable(Of TSource)
Típusparaméterek
- TSource
A . elemeinek sourcetípusa.
Paraméterek
- source
- IQueryable<TSource>
A sorozat, amelyből elemeket ad vissza.
- predicate
- Expression<Func<TSource,Int32,Boolean>>
Egy feltétel egyes elemeinek tesztelésére szolgáló függvény; a függvény második paramétere az elem indexét jelöli a forrásütemezésben.
Válaszok
Olyan IQueryable<T> elem, amely a bemeneti sorozat elemeit tartalmazza, mielőtt az elem, amelyen a megadott predicate teszt már nem halad át.
- Attribútumok
Kivételek
source vagy predicate az null.
Példák
Az alábbi példakód bemutatja, hogyan lehet TakeWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) elemeket visszaadni egy sorozat kezdetétől, amíg az elem indexét használó feltétel igaz.
string[] fruits = { "apple", "passionfruit", "banana", "mango",
"orange", "blueberry", "grape", "strawberry" };
// Take strings from the array until a string whose length
// is less than its index in the array is found.
IEnumerable<string> query =
fruits.AsQueryable()
.TakeWhile((fruit, index) => fruit.Length >= index);
foreach (string fruit in query)
Console.WriteLine(fruit);
/*
This code produces the following output:
apple
passionfruit
banana
mango
orange
blueberry
*/
Dim fruits() As String = _
{"apple", "passionfruit", "banana", "mango", _
"orange", "blueberry", "grape", "strawberry"}
' Take strings from the array until a string whose length
' is less than its index in the array is found.
Dim query = fruits.AsQueryable() _
.TakeWhile(Function(fruit, index) fruit.Length >= index)
' Display the results.
Dim output As New System.Text.StringBuilder
For Each fruit As String In query
output.AppendLine(fruit)
Next
MsgBox(output.ToString())
' This code produces the following output:
' apple
' passionfruit
' banana
' mango
' orange
' blueberry
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 TakeWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) metódus létrehoz egy olyan metódust MethodCallExpression , amely önmagát generált általános metódusként jeleníti TakeWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,Boolean>>) meg. Ezután átadja a MethodCallExpression paraméter tulajdonsága által CreateQuery(Expression) képviselt metódusnak IQueryProviderProvider.source
A meghívást TakeWhile<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32,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 az egyes elemekre predicate vonatkoziksource, amíg meg nem talál egy olyan elemet, amelynek predicate a visszaadása falsemegtörténik. Az összes elemet visszaadja addig a pontig. Az egyes forráselemek indexét a rendszer a második argumentumként adja meg.predicate