我做了[Hashtable hash],例如
hash(i, 1)
hash(j, 2)
我还制作了一个[arraylist sArray],包括" i"或" j"比如
sArray[0] : hello
sArray[1] : first number is i
sArray[2] : second number is j
sArray[3] : bye
现在,我想改变" i"和" j"在sArray中的哈希值。
我该怎么办?
答案 0 :(得分:0)
如果我理解得当,我认为这是c#中的代码
//Your example
int i = 1;
int j = 2;
var hash = new System.Collections.Hashtable();
hash[i] = -173.5;
hash[j] = 37;
var sArray = new System.Collections.ArrayList();
sArray.Add("hello");
sArray.Add("first number is " + hash[i].ToString());
sArray.Add("second number is " + hash[j].ToString());
sArray.Add("bye");
// more general, you could have different i and j position
i = 3;
j = 4;
hash[i] = 33.3;
hash[j] = -44.4;
sArray[1] = "number in " + i.ToString() + " position is " + hash[i].ToString();
sArray[2] = "number in " + j.ToString() + " position is " + hash[j].ToString();
// I think following option is more easy to read and fast if iterated
i = 5;
j = 6;
hash[i] = 55.5;
hash[j] = -66.6;
sArray[1] = String.Format("number in {0} position is {1}", i, hash[i]);
sArray[2] = String.Format("number in {0} position is {1}", j, hash[j]);