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

  • Thread starter Thread starter Andy Sutorius via DotNetMonster.com
  • Start date Start date
A

Andy Sutorius via DotNetMonster.com

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";
}
}


}
 
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
 
Here is the insertion code:

for(m=0;m<formkeys.Length;m++)
{
colKeysValues.Add(formkeys[m],Request.Form.GetValues(m));
}
colKeysValues.TrimToSize();
 
Andy Sutorius via DotNetMonster.com said:
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]);
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top