Filtering Data (Visual Basic)
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'.
The standard query operator methods that perform selection are listed in the following section.
Methods
Method Name | Description | Visual Basic Query Expression Syntax | More Information |
---|---|---|---|
OfType | Selects values, depending on their ability to be cast to a specified type. | Not applicable. | Enumerable.OfType Queryable.OfType |
Where | Selects values that are based on a predicate function. | Where |
Enumerable.Where Queryable.Where |
Query Expression Syntax Example
The following example uses the Where
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
See also
- System.Linq
- Standard Query Operators Overview (Visual Basic)
- Where Clause
- How to: Filter Query Results
- How to: Query An Assembly's Metadata with Reflection (LINQ) (Visual Basic)
- How to: Query for Files with a Specified Attribute or Name (Visual Basic)
- How to: Sort or Filter Text Data by Any Word or Field (LINQ) (Visual Basic)
GitHub पर हमारे साथ सहयोग करें
इस सामग्री का स्रोत GitHub पर पाया जा सकता है, जहाँ आप समस्याएँ बना और समीक्षा भी कर सकते हैं और अनुरोध खींच सकते हैं. अधिक जानकारी के लिए, हमारे योगदानकर्ता गाइड देखें.