Hash 的用法很簡單,同樣地,跟 array、List 一樣,可以用很簡潔的方式來表示,也就是大括號 { }
或者,也可以將符合 key、value 格式的有 IEnumerable 介面的變數傳入 Hash() 函數來取得。
h1 = { 'a': 65, 'b': 66, 'c': 67 } print h1['a'] h2 = Hash( ( ('a',65), ('b',66), ('c',67) ) ) h3 = Hash( [ ('a',65), ('b',66), ('c',67) ] )
沒有 Generic 版本的 Hash 可以參考 src/boo.lang/Hash.cs,它其實是繼承自 Hashtable﹔有 Generic 版本的,就直接參考 System.Collections.Generic 裡面的 Hash 吧~