我有一个collection
类的列表,Collection1
并希望从最初的按名称选择中获取一个给定名称“N1”的引脚列表,我应该得到那些以“.1”或(“.2”)结尾的引脚然后找到列表中的另一个连接是“.2”或(“.1”)
结果应该是与此类似的列表
R1.1
NoUse1.10
L1.2
R1.2
NoUse1.19
C1.2
C1.1
NoUse2.3
L1.1
NoUse2.11
我只得到这个
R1.1
NoUse1.10
L1.2
R1.2
L1.1
有没有办法以编程方式更新 LINQ 中的 JOIN - ON?
谢谢你
这是我的代码
Public Class Form1
Private Property connCompsNetsSel As Object
Private Property Result As IEnumerable(Of String)
Private Property Result2 As IEnumerable(Of String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim collection As New List(Of Collection1)
collection.Add(New Collection1("N1", "R1.1"))
collection.Add(New Collection1("N1", "NoUse1.10"))
collection.Add(New Collection1("N1", "L1.2"))
collection.Add(New Collection1("N2", "R1.2"))
collection.Add(New Collection1("N2", "NoUse1.19"))
collection.Add(New Collection1("N2", "C1.2"))
collection.Add(New Collection1("N3", "C1.1"))
collection.Add(New Collection1("N3", "NoUse2.3"))
collection.Add(New Collection1("N4", "NoUse2.6"))
collection.Add(New Collection1("N4", "C2.2"))
collection.Add(New Collection1("N5", "C2.1"))
collection.Add(New Collection1("N5", "C3.1"))
collection.Add(New Collection1("N6", "C7.2"))
collection.Add(New Collection1("N6", "C7.2"))
collection.Add(New Collection1("N10", "L1.1"))
collection.Add(New Collection1("N10", "NoUse2.11"))
'get initial pins from given name
Result = From cns In collection _
Where cns.Name = "N1" Select cns.Pin
'get other pins
Result2 = From cns In collection _
Join cns1 In collection On _
If(cns.Pin.ToString.Split(".")(1) = "1", cns.Pin.ToString.Split(".")(0) & ".2", cns.Pin.ToString.Split(".")(0) & ".1") Equals cns1.Pin.ToString _
Where cns.Name = "N1" Select cns1.Pin
'combine Result and Result2
Dim finalResult As New ArrayList
finalResult.AddRange(Result.ToArray)
finalResult.AddRange(Result2.ToArray)
End Sub
End Class
Public Class Collection1
Private _Name As String
Private _Pin As String
Public Sub New(ByVal Name As String, ByVal Pin As String)
_Name = Name
_Pin = Pin
End Sub
Public Property Name As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
Public Property Pin As String
Get
Return _Pin
End Get
Set(ByVal Value As String)
_Pin = Value
End Set
End Property
End Class