以下のコードを試してみて下さい。
Public Class Form1
'Button1を持っているForm
'組合せKeyを表す構造体の型定義
Private Structure Combined_Key
'VBに組み込みのInterface.Combined_Key型に、比較演算を適用できるようにする
'厳密に型指定した方が良い
Implements IEquatable(Of Combined_Key)
Public Key1 As String
Public Key2 As String
Public Sub New(ByVal Key1 As String, ByVal Key2 As String)
'初期化を行うConstractor
Me.Key1 = Key1
Me.Key2 = Key2
End Sub
'IEquatableの実装.4行目の末尾でreturnすると、以下のFunctionのスケルトンが生成される
Public Function Equals1(ByVal other As Combined_Key) As Boolean Implements System.IEquatable(Of Combined_Key).Equals
'ここは手動で書く
If (Me.Key1 = other.Key1) And (Me.Key2 = other.Key2) Then 'Meとotherが等しい事の定義
Return True '等しい場合には、Trueを返す(必須)
Else
Return False 'そうでない場合は、Falseを返す(いまは省略可)
End If
End Function
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim keyCheck As New List(Of Combined_Key) '厳密に型指定した方が早い(ArrayListと等価)
For i As Integer = 0 To 1
For j As Integer = 0 To 1
Dim SampleKey As New Combined_Key(CStr(i), CStr(j))
'Dim SampleKey As New Combined_Key
'SampleKey.Key1 = CStr(i).何かを代入しなければ、Key1はnothingのまま
'SampleKey.Key2 = CStr(j).何かを代入しなければ、Key2はnothingのまま
'と同じ
keyCheck.Add(SampleKey)
Next j
Next i
'keyCheck = {0,0),(0,1),(1,0),(1,1)}
Dim TestKey1 As New Combined_Key("0", "0") 'TestKey1 = (0,0)
Dim TestKey2 As New Combined_Key("0", "5") 'TestKey2 = (0,5)
If keyCheck.Contains(TestKey1) = False Then
MessageBox.Show("TestKey1 なし", "test", MessageBoxButtons.OK)
Else
MessageBox.Show("TestKey1 あり", "test", MessageBoxButtons.OK)
End If
If keyCheck.Contains(TestKey2) = False Then
MessageBox.Show("TestKey2 なし", "test", MessageBoxButtons.OK)
Else
MessageBox.Show("TestKey2 あり", "test", MessageBoxButtons.OK)
End If
End Sub
End Class