Answer the question
In order to leave comments, you need to log in
How to display sum of squares of numbers from ListBox?
A sequence of numbers is entered into the ListBox, for example (6,8,12). It is necessary to calculate the sum of the squares of these numbers and display in the TextBox.
I know that you don’t like such questions (write for me), but if you help me, I will be glad. I don't think it's a difficult task.
Answer the question
In order to leave comments, you need to log in
var array = new List<int>();
foreach (var item in myListBox.Items)
{
array.Add(int.Parse(item.ToString()));
}
var sum = array.Sum(x => Math.Pow(x, 2));
myTextBox.Text = sum.ToString();
var array = new[] {6, 8, 12};
var sum = array.Sum(x => Math.Pow(x, 2));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question