Class Person Sub TestingClass2() People.Add(New Person With {.Age = 16, .Name = "Angie"}) People.Add(New Person With {.Age = 20, .Name = "Brandy"}) Console.WriteLine(peopleDet1.Name) Console.WriteLine(peopleDet1.Name2) Console.ReadKey() The codes above show us how to create variable with Person type/class. There are 2 ways how to add the value in it. Here the ways: First way: Dim People As People.Add(New Person With {.Age = 16, .Name = "Angie"}) People.Add(New Person With {.Age = 20, .Name = "Brandy"}) Second way: Dim People2() = {New Person With {.Name = "Herry", .Age = 16}, _ New Person With {.Name = "Jerry", .Age = 25}} The codes up there is the same, but have a major different on it. First ways is easier when we insert the new record/value in people variable, but second ways, we easy to write because we can make it one line code, but difficult to read it and also second way not friendly if we want to insert the new record in the different line. Also, the codes above teach us how to join two variables in the simple way. I want to join 2 variables where the condition " age = 16 " and get the name of the person. Dim peopleDet = From peo In People Join peo2 In People2 On peo.Age Equals peo2.Age _ Where peo.Age = 16 Select peo.Name, Name2 = peo2.Name The result will return "Angie" and "Herry", because their age is same. Ok. Have a nice coding.. :)
Public Age As Integer
Public Name As String
End Class
Dim People As New List(Of Person)
Dim People2() = {New Person With {.Name = "Herry", .Age = 16}, _
New Person With {.Name = "Jerry", .Age = 25}}
Dim peopleDet = From peo In People Join peo2 In People2 On peo.Age Equals peo2.Age _
Where peo.Age = 16 Select peo.Name, Name2 = peo2.Name
For Each peopleDet1 In peopleDet
Next
End Sub
New List(Of Person)
Thursday, May 22, 2008
Join 2 variables with Linq (VB Express 2008)
at 9:11 AM
Subscribe to:
Post Comments (Atom)









0 comments:
Post a Comment