By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,220 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,220 IT Pros & Developers. It's quick & easy.

String variable gets value of "System.String[]"

P: n/a
Hi,

I have a Sorted List that has 9 key/value pairs. I am trying to take one of
the key/value pairs and store the value of that key into a string variable.
However, the value that actually gets inserted into the variable is "System.
String[]" and I don't understand what happened to my original value in the
key/value pair.

Thanks for your help,

Andy

snippet:

a key="strAmount"
its value="10.01"
stored in a Sorted List

string strAmount = "";

foreach(DictionaryEntry de2 in colVariableName)
{
if(de2.Key.ToString() == "strAmount")
{
strAmount = de2.Value.ToString();
if(strAmount == "")
{
strAmount = "0.00";
}
if(strAmount == "System.String[]");
{
strAmount = "0.00";
}
}
}
--
Message posted via http://www.dotnetmonster.com
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
>a key="strAmount"
its value="10.01"
stored in a Sorted List
Can you show the insertion code? It seems the value gets stored as a
string array.

strAmount = de2.Value.ToString();


If you do

strAmount = (string)de2.Value;

here instead, and it fails at runtime, you have a definite indication
that the value isn't a string.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2

P: n/a
Here is the insertion code:

for(m=0;m<formkeys.Length;m++)
{
colKeysValues.Add(formkeys[m],Request.Form.GetValues(m));
}
colKeysValues.TrimToSize();

Mattias Sjögren wrote:
a key="strAmount"
its value="10.01"
stored in a Sorted List


Can you show the insertion code? It seems the value gets stored as a
string array.
strAmount = de2.Value.ToString();


If you do

strAmount = (string)de2.Value;

here instead, and it fails at runtime, you have a definite indication
that the value isn't a string.

Mattias

--
Message posted via http://www.dotnetmonster.com
Nov 17 '05 #3

P: n/a
"Andy Sutorius via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:50***********@DotNetMonster.com...
Here is the insertion code:

for(m=0;m<formkeys.Length;m++)
{
colKeysValues.Add(formkeys[m],Request.Form.GetValues(m));


Note the plurality: GetValues - that returns an array.

Try maybe just using the indexer:
colKeysValues.Add(formkeys[m],Request.Form[m]);

----
Adam Clauss
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.