Take While 句 (Visual Basic)Take While Clause (Visual Basic)
指定された条件が true
である限り、コレクションの要素を含むようにし、残りの要素をバイパスします。Includes elements in a collection as long as a specified condition is true
and bypasses the remaining elements.
構文Syntax
Take While expression
指定項目Parts
用語Term | 定義Definition |
---|---|
expression |
必須です。Required. 次の要素をテストするための条件を表す式。An expression that represents a condition to test elements for. 式は、Boolean 値または同等の機能 (Boolean として評価される Integer など) を返す必要があります。The expression must return a Boolean value or a functional equivalent, such as an Integer to be evaluated as a Boolean . |
RemarksRemarks
Take While
句には、クエリ結果の先頭から、指定された expression
で false
が返されるまでの要素が含まれます。The Take While
clause includes elements from the start of a query result until the supplied expression
returns false
. expression
が false
を返すと、クエリでは残りのすべての要素がバイパスされます。After the expression
returns false
, the query will bypass all remaining elements. 残りの結果に対して、expression
は無視されます。The expression
is ignored for the remaining results.
Take While
句は、Where
句を使用して、特定の条件を満たすクエリからのすべての要素を含めることができるという点で、Where
句と異なります。The Take While
clause differs from the Where
clause in that the Where
clause can be used to include all elements from a query that meet a particular condition. Take While
句には、初めて条件が満たされなくなったときまでの要素が含まれます。The Take While
clause includes elements only until the first time that the condition is not satisfied. Take While
句は、順序付けされたクエリ結果を操作する場合に最も役立ちます。The Take While
clause is most useful when you are working with an ordered query result.
例Example
次のコード例では、Take While
句を使用して、注文がない最初の顧客が見つかるまで結果を取得します。The following code example uses the Take While
clause to retrieve results until the first customer without any orders is found.
Public Sub TakeWhileSample()
Dim customers = GetCustomerList()
' Return customers until the first customer with no orders is found.
Dim customersWithOrders = From cust In customers
Order By cust.Orders.Count Descending
Take While HasOrders(cust)
For Each cust In customersWithOrders
Console.WriteLine(cust.CompanyName & " (" & cust.Orders.Length & ")")
Next
End Sub
Public Function HasOrders(ByVal cust As Customer) As Boolean
If cust.Orders.Length > 0 Then Return True
Return False
End Function