Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write to a NameValueCollection

I am trying to implement a simple construct where I first clear the NameValueCollection and the write new values to it. However at the moment I can't because it is read only. Is there a way to make it not read only or a walk around? My Code:

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);
            }
like image 363
Ben Avatar asked Sep 06 '26 00:09

Ben


1 Answers

Copy it in a new NameValueCollection:

var writableCollection = new NameValueCollection(DataDictionary);
writableCollection.Add(...);
like image 195
CodeCaster Avatar answered Sep 07 '26 14:09

CodeCaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!