NameValueCollection Question

  • Thread starter Thread starter Bernie Walker
  • Start date Start date
B

Bernie Walker

Can an individual value be changed or must the entire collection for a
specific key be cleared and re added?

Bernie.
 
Bernie,

You should just be able to do this:

// pobjNameValueCollection is the NameValueCollection instance.
pobjNameValueCollection["key"] = "new value";

Hope this helps.
 
Lets say I have:
NameValueCollection nvc = new NameValueCollection():
nvc.Add("Saying","Apples");
nvc.Add("Saying","Peaches");
nvc.Add("Saying","Pumpkin Pie");

now I want to change the value of 'Pumpkin Pie' to 'Cherry Pie' for the key
'Saying'

Is there a way to access the third value of the key and change it?

Bernie.

Nicholas Paldino said:
Bernie,

You should just be able to do this:

// pobjNameValueCollection is the NameValueCollection instance.
pobjNameValueCollection["key"] = "new value";

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Bernie Walker said:
Can an individual value be changed or must the entire collection for a
specific key be cleared and re added?

Bernie.
 
Bernie,

You will have to call GetValues to get the value for the key. Once you
do that, you can replace the value you want, remove the origial values from
the list, and then re-add all the values.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Bernie Walker said:
Lets say I have:
NameValueCollection nvc = new NameValueCollection():
nvc.Add("Saying","Apples");
nvc.Add("Saying","Peaches");
nvc.Add("Saying","Pumpkin Pie");

now I want to change the value of 'Pumpkin Pie' to 'Cherry Pie' for the key
'Saying'

Is there a way to access the third value of the key and change it?

Bernie.

message news:[email protected]...
Bernie,

You should just be able to do this:

// pobjNameValueCollection is the NameValueCollection instance.
pobjNameValueCollection["key"] = "new value";

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Bernie Walker said:
Can an individual value be changed or must the entire collection for a
specific key be cleared and re added?

Bernie.
 
Back
Top