473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Confused by the NameValueCollection

I need a little clarity in the NameValueCollection.

Within the MSDN .NET 1.1 Framework help is says:

"This collection is based on the NameObjectCollectionBase class.
However, unlike the
NameObjectCollectionBase, this class stores multiple string values under
a single key."

What does this REALLY MEAN?

IS THIS CORRECT WAY?
EXAMPLE #1
Index Key Value
0 a "alpha"
1 b "beta"
2 c "charlie"
3 c "clifford"
OR does it mean
EXAMPLE #2
Index Key Value
0 a "alpha"
1 b "beta"
2 c "charlie", "clifford"
see how I am confused?


Nov 16 '05 #1
5 8267
Example 2.

NameValueCollection nvc=new NameValueCollection();

nvc.Add("A","Alpha");

nvc.Add("B","Beta");

nvc.Add("C","Charlie");

nvc.Add("C","Chumpkin");

for(int n=0; n<nvc.Count; n++)

Console.WriteLine(nvc[n]);

foreach(string s in nvc.Keys)

Console.WriteLine(nvc[s]);
--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder...aspx?FeedId=41

"anon" <an**@hotmail.com> wrote in message
news:uk*************@TK2MSFTNGP09.phx.gbl...
I need a little clarity in the NameValueCollection.

Within the MSDN .NET 1.1 Framework help is says:

"This collection is based on the NameObjectCollectionBase class.
However, unlike the
NameObjectCollectionBase, this class stores multiple string values under a single key."

What does this REALLY MEAN?

IS THIS CORRECT WAY?
EXAMPLE #1
Index Key Value
0 a "alpha"
1 b "beta"
2 c "charlie"
3 c "clifford"
OR does it mean
EXAMPLE #2
Index Key Value
0 a "alpha"
1 b "beta"
2 c "charlie", "clifford"
see how I am confused?

Nov 16 '05 #2
Hi,

see the documentaion for NameValueCollection's Add method. It says:

"If the specified key already exists in the target NameValueCollection
instance, the specified value is added to the existing comma-separated list
of values associated with the same key in the target NameValueCollection
instance."

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"anon" <an**@hotmail.com> wrote in message
news:uk*************@TK2MSFTNGP09.phx.gbl...
I need a little clarity in the NameValueCollection.

Within the MSDN .NET 1.1 Framework help is says:

"This collection is based on the NameObjectCollectionBase class.
However, unlike the
NameObjectCollectionBase, this class stores multiple string values under a single key."

What does this REALLY MEAN?

IS THIS CORRECT WAY?
EXAMPLE #1
Index Key Value
0 a "alpha"
1 b "beta"
2 c "charlie"
3 c "clifford"
OR does it mean
EXAMPLE #2
Index Key Value
0 a "alpha"
1 b "beta"
2 c "charlie", "clifford"
see how I am confused?

Nov 16 '05 #3
What if the values have a "comma" in them? How is the comma-separated list
going to know where the next "REAL" value is?


"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:eQ**************@TK2MSFTNGP12.phx.gbl...
Hi,

see the documentaion for NameValueCollection's Add method. It says:

"If the specified key already exists in the target NameValueCollection
instance, the specified value is added to the existing comma-separated list of values associated with the same key in the target NameValueCollection
instance."

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"anon" <an**@hotmail.com> wrote in message
news:uk*************@TK2MSFTNGP09.phx.gbl...
I need a little clarity in the NameValueCollection.

Within the MSDN .NET 1.1 Framework help is says:

"This collection is based on the NameObjectCollectionBase class.
However, unlike the
NameObjectCollectionBase, this class stores multiple string values

under
a single key."

What does this REALLY MEAN?

IS THIS CORRECT WAY?
EXAMPLE #1
Index Key Value
0 a "alpha"
1 b "beta"
2 c "charlie"
3 c "clifford"
OR does it mean
EXAMPLE #2
Index Key Value
0 a "alpha"
1 b "beta"
2 c "charlie", "clifford"
see how I am confused?


Nov 16 '05 #4
They are all the real value. The values share a key.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder...aspx?FeedId=41

"anon" <an**@hotmail.com> wrote in message
news:O2**************@TK2MSFTNGP10.phx.gbl...
What if the values have a "comma" in them? How is the comma-separated list going to know where the next "REAL" value is?


"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:eQ**************@TK2MSFTNGP12.phx.gbl...
Hi,

see the documentaion for NameValueCollection's Add method. It says:

"If the specified key already exists in the target NameValueCollection
instance, the specified value is added to the existing comma-separated

list
of values associated with the same key in the target NameValueCollection
instance."

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"anon" <an**@hotmail.com> wrote in message
news:uk*************@TK2MSFTNGP09.phx.gbl...
I need a little clarity in the NameValueCollection.

Within the MSDN .NET 1.1 Framework help is says:

"This collection is based on the NameObjectCollectionBase class.
However, unlike the
NameObjectCollectionBase, this class stores multiple string values

under
a single key."

What does this REALLY MEAN?

IS THIS CORRECT WAY?
EXAMPLE #1
Index Key Value
0 a "alpha"
1 b "beta"
2 c "charlie"
3 c "clifford"
OR does it mean
EXAMPLE #2
Index Key Value
0 a "alpha"
1 b "beta"
2 c "charlie", "clifford"
see how I am confused?



Nov 16 '05 #5
"anon" <an**@hotmail.com> wrote in
news:O2**************@TK2MSFTNGP10.phx.gbl:
What if the values have a "comma" in them? How is the
comma-separated list going to know where the next "REAL" value
is?

Use the GetValues() method:
using System;
using System.Collections.Specialized;

namespace ExampleNamespace
{
public class TestForm
{
[STAThread]
public static void Main()
{
NameValueCollection nvc = new NameValueCollection();

nvc.Add("A","Alpha");
nvc.Add("B","Beta");
nvc.Add("C","Charlie 1,Charlie sub-1");
nvc.Add("C","Charlie 2");

foreach(string key in nvc.Keys)
{
Console.WriteLine("Key = {0}", key);

// A key may point to multiple values. Process
// the values individually by using the GetValues method.

foreach(string value in nvc.GetValues(key))
Console.WriteLine(" Value = {0}", value);
}
}
}
}
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Walter Zydhek | last post by:
I am having a problem using the NameValueCollection type. If I remove one of the items while iterating through an collection of this type, I end up with an exception. This exception is:...
5
by: anon | last post by:
I need a little clarity in the NameValueCollection. Within the MSDN .NET 1.1 Framework help is says: "This collection is based on the NameObjectCollectionBase class. However, unlike the...
7
by: davidw | last post by:
I always use NameValueCollection. But I read an article says the only differece between Hashtable and NameValueCollection is that NameValueCollection could accept more than one value with same key?...
0
by: Yuri Vanzine | last post by:
Saw this requested awhile ago on Matthew Reynolds's blog here: http://www.dotnet247.com/247reference/msgs/11/57944.aspx Problem: often times I deal with querystring-formatted strings w/o the...
3
by: Mike Logan | last post by:
We are trying to serialize the Request.ServerVariables collection (NameValueCollection) to an XML formatted string, to insert into a database. The problem we are running into is that most of the...
4
by: Kerr | last post by:
Hi all, I've been scouring the internet for help with this problem and every occurance i've seen reconstructs the problem but no one seems to have a solution. Hoping that you guys can help me. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.