In addition to solution #1 by
Richard Deeming[
^]...
This:
Dim numbers() As Integer = {4, 3, 2}
is NOT a list.
It's an array of integers.
This is a
List(Of Integer)[
^]:
Dim myList As New List(OF Integer)()
myList.Add(4)
myList.Add(3)
myList.Add(2)
How to: Create a List of Items | Microsoft Docs[
^]
There's at least few ways to achieve that:
1.
For Each ... In ... Next[
^]
This way you know now
2.
For ... Next[
^]
Dim numbers() As Integer = {4, 3, 2}
Dim sum As Integer = 0
For i As Integer = 0 To numbers.Length -1
sum += numbers(i)
Next
Console.WriteLine("Sum: {0}", sum)
3.
While ... Loop Until or Do ... While ...[
^]
While i < numbers.Length
sum += numbers(i)
i +=1
End While
Do
sum += numbers(i)
i +=1
Loop While i < numbers.Length
For further details about loops, please reaad this:
Loop Structures (Visual Basic) | Microsoft Docs[
^]
Another way to achieve that is to use Linq:
Dim sum = numbers.Sum(Function(x) x)
See:
LINQ: .NET Language Integrated Query[
^]
Introduction to LINQ in Visual Basic | Microsoft Docs[
^]
Good luck!