' hashtable.vb Imports System Imports System.Collections Class HashTableSample Shared Sub Main() Dim ht As Hashtable = New Hashtable ' データの追加その1 ht("japan") = "日本" ht("america") = "アメリカ" ' データの追加その2 ht.Add("china", "中国") ht.Add("india", "インド") ' データの取得 Dim str As String = CType(ht("japan"), String) Console.WriteLine(str) ' 出力:日本 ' キー項目の列挙 For Each key As String In ht.Keys Console.WriteLine(key) Next ' 出力例: ' india ' japan ' america ' china ' 値項目の列挙 For Each val As String In ht.Values Console.WriteLine(val) Next ' 出力例: ' インド ' 日本 ' アメリカ ' 中国 ' キーの存在チェック If Not ht.ContainsKey("france") Then ht("france") = "フランス" End If ' 値の存在チェック Console.WriteLine(ht.ContainsValue("アメリカ")) ' 出力:True ' エントリ(キーと値)の列挙 For Each de As DictionaryEntry In ht Console.WriteLine("{0} : {1}", de.Key, de.Value) Next ' 出力例: ' india : インド ' japan : 日本 ' france : フランス ' america : アメリカ ' china : 中国 End Sub End Class ' コンパイル方法:vbc hashtable.vb