筛选是指限制结果集只包含满足指定条件的元素的作。 它也称为选定内容。
下图显示了筛选字符序列的结果。 筛选操作的谓词要求字符必须为“A”。
执行选择的标准查询运算符方法将在以下部分列出。
方法
方法名 | DESCRIPTION | 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