collection
クラスのリストがあり、「N1」という名前のピンCollection1
のリストを取得したいのですが、名前による最初の選択から、「.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