Filtering Data
.NET Framework 3.5
Filtering refers to the operation of restricting the result set to contain only those elements that satisfy a specified condition. It is also known as selection.
The following illustration shows the results of filtering a sequence of characters. The predicate for the filtering operation specifies that the character must be 'A'.
.png?cs-save-lang=1&cs-lang=vb)
The standard query operator methods that perform selection are listed in the following section.
The following example uses the where clause in C# or the Where clause in Visual Basic to filter from an array those strings that have a specific length.
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