PC Review


Reply
Thread Tools Rate Thread

Confused by the NameValueCollection

 
 
anon
Guest
Posts: n/a
 
      13th May 2004
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?




 
Reply With Quote
 
 
 
 
Bob Powell [MVP]
Guest
Posts: n/a
 
      13th May 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>
>
>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      13th May 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>
>
>
>



 
Reply With Quote
 
anon
Guest
Posts: n/a
 
      13th May 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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?
> >
> >
> >
> >

>
>



 
Reply With Quote
 
Bob Powell [MVP]
Guest
Posts: n/a
 
      13th May 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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?
> > >
> > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Chris R. Timmons
Guest
Posts: n/a
 
      14th May 2004
"anon" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> 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/
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
NameValueCollection ... shapper Microsoft ASP .NET 3 5th Mar 2007 03:55 PM
Confused by the NameValueCollection anon Microsoft Dot NET 5 14th May 2004 05:36 AM
Confused by the NameValueCollection anon Microsoft ASP .NET 5 14th May 2004 05:36 AM
Confused by the NameValueCollection anon Microsoft Dot NET Framework 7 14th May 2004 05:36 AM
Confused by the NameValueCollection anon Microsoft C# .NET 5 14th May 2004 05:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:11 AM.