473,379 Members | 1,312 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,379 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 18 '05 #1
5 924
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 18 '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 18 '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 18 '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 18 '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 18 '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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.