2015-12-10 57 views
0

如果我成立了一個字典作爲這樣的:如何附加到字典中的鍵值的數組?

set myDict = CreateObject("Scripting.Dictionary") 

我問一個用戶他的名字。

Wscript.StdOut.WriteLine "What is your name: " 
name = Wscript.StdIn.ReadLine 

然後我問用戶五個數字。

Wscript.StdOut.WriteLine "Enter a number: " 
    num1 = cint(Wscript.StdIn.ReadLine) 
Wscript.StdOut.WriteLine "Enter a number: " 
    num2 = cint(Wscript.StdIn.ReadLine) 
Wscript.StdOut.WriteLine "Enter a number: " 
    num3 = cint(Wscript.StdIn.ReadLine) 
Wscript.StdOut.WriteLine "Enter a number: " 
    num4 = cint(Wscript.StdIn.ReadLine) 
Wscript.StdOut.WriteLine "Enter a number: " 
    num5 = cint(Wscript.StdIn.ReadLine) 

,並把五個提示號碼到任何陣列使用的ArrayList

Set myArrayList = CreateObject("System.Collections.ArrayList") 
myArrayList.Add num1 
myArrayList.Add num2 
myArrayList.Add num3 
myArrayList.Add num4 
myArrayList.Add num5 

如果我在我所建立的字典添加一個鍵與name

myDict.Add name 

我可以添加myArrayList在我以前成立myDict字典中的值name

如果是這樣,如果我要循環五個數字問題,如何追加或添加到myArrayList

回答

1

字典的值可以是一個原始值以及一個數組或一個對象(像一個ArrayList),無論是這樣的:

myDict.Add name, myArrayList 

或這樣的:

​​

您可以通過名稱選擇對象來處理對象。下面將價值42追加爲新的元素添加到數組列表:

myDict(name).Add 42 

你也可以把一個新的(空)數組列表到字典事後追加你的號碼:

Set myDict(name) = CreateObject("System.Collections.ArrayList") 
Wscript.StdOut.WriteLine "Enter a number: " 
myDict(name).Add CInt(WScript.StdIn.ReadLine) 
... 
相關問題