Re: NameValueCollection's GetValues does not return multiple entries

From: Matt Berther (mberther_at_hotmail.com)
Date: 01/29/05


Date: Sat, 29 Jan 2005 12:33:53 -0800

Hello Vagif,

Can you post a small example project that demonstrates the problem you are
having?

--
Matt Berther
http://www.mattberther.com
> The strange thing is that if I use your format: <add key="Key"
> value="Value1,Value2" />
> then GetValues() returns an array that contains only the first value
> ("Value1").
> I also don't think it should work that way. NameValueCollection.Add()
> method (unlike Set) _adds_ another value to an existing key if it
> already exists, so why they implemented it differently in
> AppSettingReader?
> 
> Vagif
> 
> "Matt Berther" <mberther@hotmail.com> wrote in message
> news:8018000632425943734822023@news.microsoft.com...
> 
>> Hello Vagif,
>> 
>> A key is supposed to be unique. I think what you are after is this:
>> 
>> <add key="Key" value="Value1,Value2" />
>> 
>> The NameValueCollection returns a string array based on a string
>> split on ','.
>> 
>> --
>> Matt Berther
>> http://www.mattberther.com
>>> When I use AppSettings and try to retrieve multiple values
>>> associated with a single key, I only get the last value. E.g. if I
>>> have in my config
>>> 
>>> <appSettings>
>>> <add key="Key" value="Value1" />
>>> <add key="Key" value="Value2" />
>>> </appSettings>
>>> then attempt to read both values by using
>>> AppSettings.GetValues("Key")
>>> gives only "Value2".
>>> This is not what's written in .NET Framework documentation which
>>> says:
>>> 
>>> "NameValueCollection collection is based on the
>>> NameObjectCollectionBase class. However, unlike the
>>> NameObjectCollectionBase, this class stores multiple string values
>>> under a single key."
>>> 
>>> And the whole purpose og GetValues is to retrieve multiple values,
>>> ulike an indexer that only returns a single value. It does return a
>>> string array, but only with a single value.
>>> 
>>> What can be wrong?
>>> 
>>> Vagif Abilov
>>> 
>>> vagif @ online.no
>>> 


Relevant Pages

  • Re: Sorting a variant array
    ... Anyway, the point is tempList will become a 2D array, even if its one column ... move the Variant array into a String array which is what I thought might ... try and move them to a string array I get no debug output and ... Even if I don't try the movement to a String Array the sorting algorithm ...
    (microsoft.public.excel.programming)
  • Re: NameValueCollections GetValues does not return multiple entries
    ... > Hello Vagif, ... > The NameValueCollection returns a string array based on a string split on ... >> And the whole purpose og GetValues is to retrieve multiple values, ... >> string array, but only with a single value. ...
    (microsoft.public.dotnet.framework)
  • Re: fixed or dynamic array
    ... Split to a pre dimensioned variant array fails, ... ReDim vas Variant ... If you had instead used Dim arrStr then the Split function would have failed, because arrStr would be a static array and the Split function needs a dynamic array. ... The Split function needs either a dynamic array into which it will place its output or a normal Variant into which it will place a string array containing its output. ...
    (microsoft.public.vb.general.discussion)
  • Re: a string, a string array and character array
    ... as a "character array", the term used in the rest of Matlab. ... You might be confused by references to a "cell string array" or a "cell array ...
    (comp.soft-sys.matlab)
  • Re: Creating Optional Commandline Parameters
    ... Rather, Environment.GetCommandLineArgs, which returns a string array... ... My apologies. ... Matt Berther ...
    (microsoft.public.dotnet.framework.windowsforms)