Wednesday, February 25, 2009

Using LINQ To Query The Result

Hi, in this section we will have glance at the querying language gifted by Microsoft. Using LINQ(.NET Language-Integrated Query) we can search an array of values and get the result as we do in the databases. A small example for this is

Dim arrValues As ArrayList = New ArrayList

arrValues.Add(1)
arrValues.Add(15)
arrValues.Add(4)
arrValues.Add(13)
arrValues.Add(21)
arrValues.Add(10)
arrValues.Add(7)
arrValues.Add(17)
arrValues.Add(3)

Dim arrRes As IEnumerable(Of Integer)= From s _
As Integer In arrValues Where s >= 10
Dim temp As String = ""
For Each nTemp As Integer In arrRes
temp = temp + Convert.ToString(nTemp) + ","
Next
MsgBox(temp)



You can even give Order or your search as below.

Dim arrRes As IEnumerable(Of Integer)= From s _
As Integer In
arrValues Where s >= 10 Order By s


or Sort Descendingly by using as below.

Dim arrRes As IEnumerable(Of Integer)= From s _
As Integer In arrValues Where s >= 10 Order By s Descending


You can get more information on LINQ at
Microsoft Link LINQ: .NET Language-Integrated Query

Happy Learning :)



No comments:

Post a Comment