473,385 Members | 1,402 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,385 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?


Jul 21 '05 #1
5 1652
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?

Jul 21 '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?

Jul 21 '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?


Jul 21 '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?



Jul 21 '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/
Jul 21 '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. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.