我正在尝试实现一个简单的构造,我首先清除NameValueCollection并为其写入新值。但是目前我不能因为它是只读的。有没有办法让它不是只读或四处走动? 我的代码:
NameValueCollection DataDictionary = ConfigurationManager.GetSection("dataDictionary") as NameValueCollection;
DataDictionary.Clear();
for (int i = 0; i < tableLayoutPanel2.RowCount; i++)
{
var T = tableLayoutPanel2.GetControlFromPosition(1, i);
var T2 = tableLayoutPanel2.GetControlFromPosition(3, i);
string key = T.Text;
string value = T2.Text;
DataDictionary.Add(key, value);
}
答案 0 :(得分:0)
将其复制到new NameValueCollection
:
var writableCollection = new NameValueCollection(DataDictionary);
writableCollection.Add(...);