Dictionaryオブジェクト
概要
Dictionaryオブジェクトの使い方基本。
「.NET Framework version 2.0」から追加されて「Dictionary ジェネリック クラス」と呼ぶ。
「.NET Framework version 2.0」から追加されて「Dictionary ジェネリック クラス」と呼ぶ。
参照
前提条件
手順
default.aspx に GridView を 「GridView1」というIDで配置する。
default.aspx.vb を以下のように変更する。
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' 宣言&初期化
Dim dic_temp As Dictionary(Of String, String) = New Dictionary(Of String, String)
' キーと値を登録
dic_temp.Add("キーA", "バリューA")
dic_temp.Add("キーB", "バリューB")
' 通常の値の取出し方
Dim str_disp_temp = ""
For Each str_key In dic_temp.Keys
Dim str_value = ""
dic_temp.TryGetValue(str_key, str_value)
str_disp_temp += str_key + " : " + str_value
str_disp_temp += "<br>"
Next
Response.Write(str_disp_temp)
' GridViewにデータバインド可能
GridView1.DataSource = dic_temp
GridView1.DataBind()
End Sub
End Class
実行結果。
not found (1.jpg)
C#でやる場合の、宣言&初期化は以下の通り。
Dictionary<String, String> dic_rtn = new Dictionary<string, string>();