sum

J

Joanna Carter [TeamB]

"Hrvoje Voda" <[email protected]> a écrit dans le message de [email protected]...

| How to make a Sum of listBox items?

Assuming all the items in the listbox are string representations of integers
:

{
int total = 0;

foreach (object o in listbox1.Items)
{
total += (int) Convert.ChangeType(o, typeof(int));
}
}

Joanna
 
J

Joanna Carter [TeamB]

"Simon Hart" <srhartone@[no spam]yahoo.com> a écrit dans le message de uEcIlm%[email protected]...


| Or just simply:
|
| int count = listbox.Items.Count;

Huh ? The term Sum means the total of all the values, not the Count.

Joanna
 
R

Richard Blewett [DevelopMentor]

Joanna Carter said:
"Simon Hart" <srhartone@[no spam]yahoo.com> a écrit dans le message de
uEcIlm%[email protected]...


| Or just simply:
|
| int count = listbox.Items.Count;

Huh ? The term Sum means the total of all the values, not the Count.

Joanna

Well it depends on context

If I asked for the sum total of items in the list I'd probably be after the
count. but if I asked for the sum of the items I'd probablt be asking got
the the sum across each item in teh list.

The problme is that on an English newsgroup in a heavily non-English
speaking world then both interpretations are valid and the OP needs to
provide more context.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
 

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

Similar Threads

remove from listBox 3
remove selected item 1
array list 15
listbox search 1
doc file 3
check disabled 3
checked listbox check all 3
ckecked listbox 4

Top