連想配列 Dictionary ジェネリック VB.NET入門

Dictionary 連想配列 ジェネリック

Hashtableのジェネリック番がDictionaryです。

宣言
構文
Dim 変数名 As New Dictionary

追加
構文
変数名Add(キー, データ)

参照
構文
変数名(キー)

ソース
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Dictionary As New Dictionary(Of String, Integer)

Dictionary.Add(“マリオ”, 80)
Dictionary.Add(“クッパ”, 77)
Dictionary.Add(“ピーチ”, 99)

MsgBox(Dictionary(“マリオ”))

End Sub
End Class

実行結果は
80です。

Hashtableの記事を置き換えてこのページは作成してます。
vsでも検索と置き換えは出来るのでHashtableを検索Dictionaryを置き換えれば楽でした。
ofキーワードは書き足しましたが。

コレクションとジェネリックを解説してきましたが一般的にはジェネリックを使うみたいですね。
一応知ってても損はないので書くことにしました。

シェアする

  • このエントリーをはてなブックマークに追加

フォローする

Translate »