Dictionary Dictionary _dic = new Dictionary();Hashtable _ht = new Hashtable();while (_dr.Read()){_ht.Clear();for (int i = 0; i < _dr.FieldCount; i++){_ht.Add(_dr.GetName(i),_dr[i]);}_dic.Add(_i,_ht);_i++;}我原本是想循环记录集并将其添加
来源:学生作业学帮网 编辑:学帮网 时间:2024/06/09 11:49:21
Dictionary
Dictionary _dic = new Dictionary();
Hashtable _ht = new Hashtable();
while (_dr.Read())
{
_ht.Clear();
for (int i = 0; i < _dr.FieldCount; i++)
{
_ht.Add(_dr.GetName(i),_dr[i]);
}
_dic.Add(_i,_ht);
_i++;
}
我原本是想循环记录集并将其添加到hashtable中,再将记录依次添加到dictionary里.但是每次循环后,dictionary里hashtable的值都变掉了(就是dictionary 和 dictionary里的所有hashtable都同步更新,都是一个值.),该怎么改才能实现我要的结果呢?
Dictionary _dic = new Dictionary();
Hashtable _ht;
while (_dr.Read())
{
_ht=new Hashtable(); // 每个循环都创建一个新的对象
for (int i = 0; i < _dr.FieldCount; i++)
{
_ht.Add(_dr.GetName(i), _dr[i]);
}
_dic.Add(_i, _ht);
_i++;
}
dictionary放的是hashtable对象的引用.因为你只new 了一个hashtable对象,当然会出现同步更新的现象了.解决办法是每个循环都new一个hashtable对象.
The dictionary is very expensive.Linda can't buy it.改为Linda hasn't _____ _____to buythe dictionar应该改为Linda isn't _____ _____to buythe dictionar
Is this his dictionar?(改为肯定句)()()his dictionary.一个( )里只能填一个词.
英语.改同义句.1.She paid ten dollars for the dictionary.改为 She _ ten dollars _ the dictionar...英语.改同义句.1.She paid ten dollars for the dictionary.改为 She _ ten dollars _ the dictionary. 2.There isn't anything wrong with my wat
dictionary
dictionary
1.they will come tomorrow if they are not prevented 为什么用if 不用whether2.we are to perform a new experiment this afternoon 可以把are to perform 换成will be to perform 3.can you tell me whom the dictionary belong to 的whom the dictionar
dictionary是什么意思dictionary是什么意思
dictionary复数
_____it____English dictionary?
oxford dictionary
dictionary中文
dictionary是什么意思
dictionary是什么意思
DICTIONARY怎么样
dictionary咋念
_________is_________English dictionary
mini-dictionary
English--English dictionary 翻译