■ 宣言 / New
List
Dim list = New List(Of String)
Dictionary
Dim words As New Dictionary(Of String, String)
■ 初期化 / 値の取得
List
Dim list As New List(Of String)) (New String() { "associate", "concerns" }) ' From キーワードを使って、コレクション用に初期化する Dim values As New List From { New SampleClass With {.Id = "X001", .Name = "Mike"}, New SampleClass With {.Id = "X002", .Name = "Tom"} } ' 値の取得 Dim value = values(0)
参考文献
http://d.hatena.ne.jp/PoohKid/20071211/maphttp://vbegg.webcrow.jp/windowsforms/initialize.html
Dictionary
* .NET Framework 4.0以降らしいDim words = New Dictionary(Of String, String)() From _ { {"associate", "関係づける,連想する."}, {"concerns", "興味,関心"} } ' 値の取得 Dim word = words("concerns")
参考文献
http://d.hatena.ne.jp/qaz76/20110222/1299167727http://www.atmarkit.co.jp/fdotnet/chushin/vb2010features_01/vb2010features_01_03.html
■ ループ
List
Dim values As New List(Of String)) (New String() { "associate", "concerns" }) For Each value As String In values ' ループ処理 Next
参考文献
http://homepage1.nifty.com/rucio/main/VBdotNet/Samples201/Sample205ForEachNext.htmDictionary
Dim words = New Dictionary(Of String, String)() From _ { {"associate", "関係づける,連想する."}, {"concerns", "興味,関心"} } For Each word As KeyValuePair(Of String, String) In words Console.WriteLine("{0} : {1}", word.Key, word.Value) Next
参考文献
http://www.atmarkit.co.jp/fdotnet/dotnettips/429dictionary/dictionary.html■ ソート
Dictionary
// キーでソート For Each word As KeyValuePair(Of String, String) In words.OrderBy(Function(val) val.Key) // 値でソート For Each word As KeyValuePair(Of String, String) In words.OrderBy(Function(val) val.Value) // キーでソート For Each word As KeyValuePair(Of String, String) In words.OrderByDescending(Function(val) val.Key) // 値でソート For Each word As KeyValuePair(Of String, String) In words.OrderByDescending(Function(val) val.Value)