Dictionary 物件以「鍵/值」對方式儲存資料,比陣列更適合處理關聯性資料,提供豐富內建方法。
<%
Dim d
Set d = Server.CreateObject("Scripting.Dictionary")
d.Add "re", "Red"
d.Add "gr", "Green"
d.Add "bl", "Blue"
d.Add "pi", "Pink"
Response.Write("鍵 gr 的值為: " & d.Item("gr"))
%>
輸出: 鍵 gr 的值為: Green
ReDim 即可動態增減Exists, Keys, Items 等)| 屬性 | 描述 |
|---|---|
| CompareMode | 設定/傳回鍵比較模式 (二進位/文字/資料庫比較) |
| Count | 傳回鍵/值對總數 |
| Item | 設定/傳回指定鍵的值 |
| Key | 變更現有鍵的值 |
| 方法 | 描述 |
|---|---|
| Add | 新增鍵/值對 |
| Exists | 檢查鍵是否存在,傳回布林值 |
| Items | 傳回所有值的陣列 |
| Keys | 傳回所有鍵的陣列 |
| Remove | 移除指定鍵/值對 |
| RemoveAll | 清空所有項目 |
實務應用:常用於快取設定、Session 替代方案、表單驗證規則儲存等場景。現代 ASP.NET 建議改用 System.Collections.Generic.Dictionary<TKey, TValue>。