具有单个键的多个值的哈希表 [英] Hashtable with multiple values for single key

查看:119
本文介绍了具有单个键的多个值的哈希表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单个键中存储多个值,例如:

I want to store multiple values in single key like:

HashTable obj = new HashTable();
obj.Add("1", "test");
obj.Add("1", "Test1");

现在这会引发错误.

推荐答案

您可以将test,test1,test2,...放在表中,然后将此表放在Hashtable中,作为键的值,这对于所有键都是相同的.

you can put your test,test1,test2,... in a table and then put this table in a Hashtable as a value for the key which will be the same for all them.

例如,尝试如下操作:

List<string> list = new List<string>();
list.Add("test");
list.Add("test1"); 

然后:

HashTable obj = new HashTable();
obj.Add("1", list);

这篇关于具有单个键的多个值的哈希表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆