In this tutorial, we will getting sum of all numbers in the listbox.
First, We’ll design the form.
Source Code: (Button1_Click)
1 2 3 4 5 6 7 8 9 10 11 | private void button1_Click(object sender, EventArgs e) { decimal sum = 0; for(int i=0;i<listBox1.Items.Count;i++) { sum += Convert.ToDecimal(listBox1.Items[i]); } label1.Text = "Sum all the Numbers : " + sum; } |
Output: