Select Operator in Linq
The Select operator is used to select value from the collection.
Understanding select
The below defines the
names can be an array of numbers, strings,
or even objects. Here is an example of names.
Dim names As String() = {"Java", "C#", "Javascript", "SQL", "Oracle", "Python", "C++", "C", "HTML", "CSS"}
The select syntax in LINQ is similar to select clause of SQL.
Here is a simple select.
Dim query As IEnumerable(Of String) = From n In names Select n
In the above statement, we select n in names.
For example
The below code defines the select items in LinQ using VB.NET.
Module Module1
Public Sub Main()
Dim names As String() = {"Java", "C#", "Javascript", "SQL", "Oracle", "Python", "C++", "C", "HTML", "CSS"}
Dim query As IEnumerable(Of String) = From n In names Select n
For Each s As [String] In query
Console.WriteLine(s)
Next
End Sub
End Module
OUTPUT
Select with where operator
The Where operator is used to filter the items.
The following code selects items from an array that have value below 6.
Module Module1
Public Sub Main()
Dim numbers = New Integer() {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
Dim a = From num In numbers Where num < 6 Select num
Console.WriteLine("Numbers < 5:")
For Each n In a
Console.WriteLine(n)
Next
End Sub
End Module
OUTPUT