🌷
VB.Net で Collectionを扱うサンプル
初期化
''' <summary>
''' List
''' </summary>
Dim animals As New List(Of String)(New String() {"dog", "cat", "monkey"})
Dim numbers As New List(Of Integer) From {{10}, {20}, {30}}
''' <summary>
''' Dictionary
''' </summary>
Dim wdic As New Dictionary(Of Integer, String) From {{1, "one"}, {2, "Two"}}
DictionaryのMerge
''' <summary>
''' DictionaryのMerge
''' </summary>
Public Shared Function MergeDictionary(Of TKey, TValue)(
first As Dictionary(Of TKey, TValue),
second As Dictionary(Of TKey, TValue)) As Dictionary(Of TKey, TValue)
If (second Is Nothing) Then
Return first
End If
If (first Is Nothing) Then
first = New Dictionary(Of TKey, TValue)()
End If
For Each kv As KeyValuePair(Of TKey, TValue) In second
If (first.ContainsKey(kv.Key)) Then
first(kv.Key) = kv.Value
Else
first.Add(kv.Key, kv.Value)
End If
Next
Return first
End Function
Discussion