我试图更新我的程序设置,它们存储在字典中。奇怪的是,如果他们被存储在一个DatabaseContext中,下面的函数将工作(我认为),但由于他们在一个字典中,我得到一个编译器错误。为什么我的KeyValuePair.Value只读?更重要的是,如何重新编写以下函数来实际更新字典?C#用LINQ查询更新字典<字符串,字符串>
感谢
public void putSetting(Dictionary<string, string> settings, string setting, string value)
{
var qry = (from s in settings
where s.Key == setting
select s).Single();
qry.Value = value; // Error 1 Property or indexer
// 'System.Collections.Generic.KeyValuePair<string,string>.Value'
// cannot be assigned to -- it is read only
}
谢谢,你们是摇滚明星! – BenMaGoo 2011-04-02 18:46:19