只要指定的條件為 true ,就會略過集合中的專案,然後傳回其餘專案。
語法
Skip While expression
組件
| 術語 | 定義 |
|---|---|
expression |
必須的。 表達式,表示要測試項目的條件。 運算式必須傳回 Boolean 值或功能對等專案,例如 Integer 要評估為 Boolean的 。 |
備註
子 Skip While 句會從查詢結果的開頭略過元素,直到提供的 expression 傳回 false為止。 傳false回 之後expression,查詢會傳回所有剩餘的專案。
expression忽略其餘結果 。
子 Skip While 句與 Where 子句不同,因為 Where 子句可用來從不符合特定條件的查詢中排除所有元素。 子 Skip While 句只會排除元素,直到第一次不符合條件為止。 當您使用已排序的查詢結果時,子 Skip While 句最有用。
您可以使用 子句,從查詢結果的開頭略過特定數目的結果 Skip 。
範例
下列程式代碼範例會使用 Skip While 子句略過結果,直到找到美國的第一個客戶為止。
Public Sub SkipWhileSample()
Dim customers = GetCustomerList()
' Return customers starting from the first U.S. customer encountered.
Dim customerList = From cust In customers
Order By cust.Country
Skip While IsInternationalCustomer(cust)
For Each cust In customerList
Console.WriteLine(cust.CompanyName & vbTab & cust.Country)
Next
End Sub
Public Function IsInternationalCustomer(ByVal cust As Customer) As Boolean
If cust.Country = "USA" Then Return False
Return True
End Function