I have:
Dim aList As List(Of myObj.Answers) = myObj.GetResults(someID)
How can I get the sum of aList.AnswerCount field in my List(Of myObj) ?
I have:
Dim aList As List(Of myObj.Answers) = myObj.GetResults(someID)
How can I get the sum of aList.AnswerCount field in my List(Of myObj) ?
Sure, I can help you with that. Here are the steps on how to sum a field in a list in VB.NET:
VB.Net
Button1_Clickevent handler will be executed. The code will iterate through the items in the ListBox control and add the values of the items to the sum variable. The sum variable will then be printed on the console.Here is an explanation of the code:
For Eachloop is used to iterate through the items in the ListBox control.Valueproperty of the ListItem control returns the value of the item.Sumvariable is used to store the sum of the values of the items in the ListBox control.Console.WriteLinemethod is used to print the sum on the console.aList.Sum(Function(i) i.AnswerCount)