0

Hi, i had write the following code but it seems like gt exception, can help me check got what problem?

 Dictionary<string, double> sortList4 = new Dictionary<string, double>();
 List<double> list = ISUPP.Items.OfType<double>().ToList();                                                      
                double[] value1=list.ToArray();
                int c = 0;
                foreach (string gk in Comset2.Items)
                {
                    sortList4.Add(gk, value1[0]);
                    c++;
                }

Edited by mike_2000_17: Fixed formatting

3
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by leo88
0

This line

sortList4.Add(gk, value1[0]);

is going to assign the same value to every entry in your list. Did you mean to say

sortList4.Add(gk, value1[c]);

?

0

Oh, sorry, i post wrong, see codes below:

            List<double> list = ISUPP.Items.OfType<double>().ToList();                                                      
            double[] value1=list.ToArray();
             foreach (string gk in Comset2.Items)
                {
                    sortList4.Add(gk,1);
                }

            int c = 0;
                foreach (string myKey in sortList4.Keys)
                {                       
                        double Count = (double)sortList4[myKey];
                        sortList4[myKey] =value1[0] ;                          
                        c++;                      
                }

Comset and ISUPP are listbox, the content of ISUPP are:

1
1
1
1
1
1
1
//something like that

Edited by mike_2000_17: Fixed formatting

0

i already change to value1[c], but still the same, got ecxception thr..

0

Two things:
Use [code] [/code] tags around your code. It makes it much easier to read and refer to.
What exception and what line is throwing the exception?

0

Lol, this post isnt good either.
Find out way by your self.


a tip: i have an issue with this code:

data = table.Rows[i]["Name"];
if(data < 10 ? _value1 + 2 : _value2 - 2;

If you find out what would be probem here, then I will find whats the matter in your code.

Edited by Mitja Bonca: n/a

0

The problem is around the codes below:

int c = 0;
foreach (string myKey in sortList4.Keys)
{ 
double Count = (double)sortList4[myKey];
sortList4[myKey] =value1[0] ; 
c++; 
}

when i execute here, it will jump to my catch statement..
//my catch statement
catch (Exception)
{
MessageBox.Show("Please put only numbers");

}

0

List<double> list = ISUPP.Items.OfType<double>().ToList();
Or got any method to pass the list to the sortList4 (value)?

0

Oh ya, the line throw the exception is here:

sortList4[myKey] =value1[c] ;

when program until here , it will jump out to catch..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.