篩選是指限制結果集只包含滿足指定條件的元素的作業。 也稱為選擇。
下圖顯示篩選字元序列的結果。 篩選作業的述詞指定字元必須是 『A』。
執行選取的標準查詢運算符方法會列在下一節中。
方法
| 方法名稱 | 說明 | Visual Basic 查詢表達式語法 | 詳細資訊 |
|---|---|---|---|
| OfType | 根據是否能轉換為指定型別來選擇值。 | 不適用。 | Enumerable.OfType Queryable.OfType |
| 哪裡 | 選取以述詞函式為基礎的值。 | Where |
Enumerable.Where Queryable.Where |
查詢運算式語法範例
下列範例會使用 Where 從陣列篩選具有特定長度的字串。
Dim words() As String = {"the", "quick", "brown", "fox", "jumps"}
Dim query = From word In words
Where word.Length = 3
Select word
Dim sb As New System.Text.StringBuilder()
For Each str As String In query
sb.AppendLine(str)
Next
' Display the results.
MsgBox(sb.ToString())
' This code produces the following output:
' the
' fox