如何保存 Dictionary 中的键与值? Dictionary<string, string[]> temp = new Dictionary<string, string[]>(); temp只是一个临时变量,经过运算赋值后,下次又赋不同的值,如何保存前面的结果呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 viewstate保存Dictionary泛型类派生并实现IXmlSerializablepublic class ComponentsProperties : Dictionary<string, Dictionary<string,string>>, System.Xml.Serialization.IXmlSerializable{ #region IXmlSerializable Members public System.Xml.Schema.XmlSchema GetSchema() { throw new NotImplementedException(); } public void ReadXml(System.Xml.XmlReader reader) { if (reader.IsEmptyElement) return; reader.Read(); while (reader.NodeType != System.Xml.XmlNodeType.EndElement) { string key = reader.Name; this[key] = new Dictionary<string, string>(); if (!reader.IsEmptyElement) { reader.ReadStartElement(); while (reader.NodeType != System.Xml.XmlNodeType.EndElement) this[key][reader.Name] = reader.ReadElementString(); } reader.Read(); } } public void WriteXml(System.Xml.XmlWriter writer) { foreach (string key in this.Keys) { writer.WriteStartElement(key); foreach (string key1 in this[key].Keys) writer.WriteElementString(key1, this[key][key1]); writer.WriteEndElement(); } } #endregion} Dictionary<string, string[]>第二个类型是string[]数组呀。 List<Dictionary<string, string[]>> tempListadd进去不就可以了 你是说string[]吧?每次都Clone一下才行。lz先理解一下引用类型和值类型吧! List<T>定义属性Dictionary<string, string[]>>实现保持序列化保存 如何释放程序对文件的占用 ASP.NET 2.0 中跨网页提交的三种方法 如何获取winform中正在运行的Timer计时器 各位大哥帮帮忙,如何重画TabControl控件的外观? 谁知道这个错误 如何用C#的webform做像qq分组那样的拉框,下面有子项的? 妹子求救 linq 左关联问题 qq:897657745 超级简单的问题,菜单显示的问题,知道的就来领分好了! ^_^ ^_^ NetMessageBufferSend在C#中到底要如何调用啊? 193错误,已经奋斗3昼夜,格式化过,换过操作系统,用过光盘镜像 c#如何实现网页内容变化显示 简单而无法解决的问题 高手 小跑进
Dictionary泛型类派生并实现IXmlSerializable
public class ComponentsProperties : Dictionary<string, Dictionary<string,string>>, System.Xml.Serialization.IXmlSerializable
{
#region IXmlSerializable Members
public System.Xml.Schema.XmlSchema GetSchema()
{
throw new NotImplementedException();
} public void ReadXml(System.Xml.XmlReader reader)
{
if (reader.IsEmptyElement)
return; reader.Read();
while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
{
string key = reader.Name;
this[key] = new Dictionary<string, string>();
if (!reader.IsEmptyElement)
{
reader.ReadStartElement();
while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
this[key][reader.Name] = reader.ReadElementString();
}
reader.Read();
}
} public void WriteXml(System.Xml.XmlWriter writer)
{
foreach (string key in this.Keys)
{
writer.WriteStartElement(key);
foreach (string key1 in this[key].Keys)
writer.WriteElementString(key1, this[key][key1]);
writer.WriteEndElement();
}
}
#endregion
}
lz先理解一下引用类型和值类型吧!
Dictionary<string, string[]>>实现保持
序列化保存