Confused by the NameValueCollection

Discussion in 'ASP .Net' started by anon, May 13, 2004.

  1. anon

    anon Guest

    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?
    anon, May 13, 2004
    #1
    1. Advertising

  2. 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);


    --
    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/GetFeed.aspx?FeedId=41





    "anon" <> wrote in message
    news:...
    > 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?
    >
    >
    >
    >
    Bob Powell [MVP], May 13, 2004
    #2
    1. Advertising

  3. anon

    Teemu Keiski Guest

    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" <> wrote in message
    news:...
    > 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?
    >
    >
    >
    >
    Teemu Keiski, May 13, 2004
    #3
  4. anon

    anon Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > 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?
    > >
    > >
    > >
    > >

    >
    >
    anon, May 13, 2004
    #4
  5. 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/GetFeed.aspx?FeedId=41





    "anon" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:...
    > > > 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?
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Bob Powell [MVP], May 13, 2004
    #5
  6. "anon" <> wrote in
    news::

    > 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/
    Chris R. Timmons, May 14, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Miller
    Replies:
    1
    Views:
    1,059
    Mark Miller
    Jul 18, 2003
  2. Yuri Vanzine
    Replies:
    0
    Views:
    2,804
    Yuri Vanzine
    Aug 18, 2003
  3. Alfons Puig
    Replies:
    1
    Views:
    1,506
    Shaji
    Aug 28, 2003
  4. Julia
    Replies:
    1
    Views:
    499
    Girish bharadwaj
    Sep 23, 2004
  5. =?Utf-8?B?TWlrZSBMb2dhbg==?=

    NameValueCollection Serialization Deserialization

    =?Utf-8?B?TWlrZSBMb2dhbg==?=, Dec 22, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,943
    Karl Seguin
    Dec 23, 2004
Loading...

Share This Page