2 c# mono hashtable monodevelop ios-simulator
如果我有相同键的多个值,那么如何在哈希表中添加它,例如:
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";
Run Code Online (Sandbox Code Playgroud)
这只是哈希表中的最后一组,即
hs["id"]= "x003.xhtml";
hs["media-type"]= "application/xhtm+xml";
hs["href"]= "text/003.xhtml";
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题....提前感谢!!
哈希表定义为具有唯一键,索引器替换现有值.听起来你真的想要一个对象列表,即
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 = "..." }
};
Run Code Online (Sandbox Code Playgroud)
同
public class YourType {
public string Id {get;set;}
public string MediaType {get;set;}
public string Href {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
(或类似的)