|
Imports System.Linq
Public Class Program
Shared Sub Main()
TestJoin()
End Sub
'let 運算子
Shared Sub UseLet()
Dim list As String() = {"Code6421 Huang", "Tom Do", "Cathy Chang"}
Dim result = From s1 In list _
Let words = s1.Split(" ") _
From word In words _
Let w = word.ToLower() _
Where w(0) = "c" _
Select word
For Each item In result
Console.WriteLine(item)
Next
Console.ReadLine()
End Sub
'lambda expression for vb.net
Shared Sub TestLastWithCondition()
Dim numbers() = {8, 9, 10, 7}
Console.WriteLine(numbers.Last(Function(x) x > 7))
Console.ReadLine()
End Sub
'匿名型別
'join運算式
Shared Sub TestJoin()
Dim p1() = {New With {.Name = "code6421", .Address = "Taipai"}, _
New With {.Name = "tom", .Address = "Taipai"}, _
New With {.Name = "jeffray", .Address = "NY"}}
Dim p2() = {New With {.Name = "code6421", .Title = "Manager"}, _
New With {.Name = "tom", .Title = "Director"}, _
New With {.Name = "jeffray", .Title = "Programmer"}}
Dim p3() = {New With {.Name = "code6421", .Hand = "Right"}, _
New With {.Name = "tom", .Hand = "Right"}, _
New With {.Name = "jeffray", .Hand = "Left"}}
Dim p4 = From s In p1 _
Join s1 In p2 On s.Name Equals s1.Name _
Join s2 In p3 On s.Name Equals s2.Name _
Select New With {.Name = s.Name, .Address = s.Address, .Title = s1.Title, .Hand = s2.Hand}
For Each item In p4
Console.WriteLine("Name {0}, Address {1}, Title {2}, Hand {3}", item.Name, item.Address, item.Title, item.Hand)
Next
Console.ReadLine()
End Sub
End Class
|