In this tutorial, we will getting average of all numbers in the listbox.
First, We’ll design the form.
Sorce Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
private void button1_Click(object sender, EventArgs e) { double avg = 0,sum=0; int lstCount = listBox1.Items.Count; //Get Count of Listbox Items for(int i=0;i< lstCount; i++) { sum += Convert.ToDouble(listBox1.Items[i]); } avg = sum / lstCount; label1.Text = "Average : " + avg; } |
Output:
I tried to figure this out for over an hour before stumbling on your site. Appreciate the help!!