c# - 单键具有不同值的哈希表

标签 c# mono ios-simulator hashtable monodevelop

如果我对同一个键有多个值,那么如何将它添加到哈希表中 例如:

                   Hashtable hs = new Hashtable();
                      hs["id"]= "x001.xhtml";
                      hs["media-type"]= "application/xhtm+xml"; 
                      hs["href"]= "text/001.xhtml";

                      hs["id"]= "x002.xhtml";
                      hs["media-type"]= "application/xhtm+xml";
                      hs["href"]= "text/002.xhtml";

                     hs["id"]= "x003.xhtml";
                     hs["media-type"]= "application/xhtm+xml";
                     hs["href"]= "text/003.xhtml";

这只取哈希表中的最后一组,即

                     hs["id"]= "x003.xhtml";
                     hs["media-type"]= "application/xhtm+xml";
                     hs["href"]= "text/003.xhtml";

如何解决这个问题....提前致谢!!

最佳答案

哈希表被定义为具有唯一键,索引器替换现有值。听起来您实际上想要一个对象列表,即

var list = new List<YourType> {
    new YourType { Id = "x001.xhtml", MediaType = "...", Href = "..." },
    new YourType { Id = "x002.xhtml", MediaType = "...", Href = "..." },
    new YourType { Id = "x003.xhtml", MediaType = "...", Href = "..." }
};

public class YourType {
    public string Id {get;set;}
    public string MediaType {get;set;}
    public string Href {get;set;}
}

(或类似的)

关于c# - 单键具有不同值的哈希表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10846215/

相关文章:

c# - 使用命令行单声道构建 zeromq helloworld 示例

objective-c - iOS设备和iPhone模拟器的内存组织差异

xcode - 为什么iOS6模拟器删除应用程序很慢?

c# - 如何将一个对象转换成它的类型?

c# - javascript pageLoad 函数未在 asp.net Site.Master 中触发

c# - 在对象列表中的所有名称之间添加逗号

c# - C# 中方法表存储在哪里?

c# - HTTPS POST/GET 不适用于 Mono

macos - 错误 MSB4057 : The target "Pack" does not exist in the project - Visual Studio for Mac

ios - 在 iPhone 模拟器中关闭声音