I know that this has already been answered, and probably most people regularly come here to answer. @pylover's answer is correct, but to add it, you can avoid iterating over all elements simply by calling the Sum() function. Thus,
Function Sum(ByVal ParamArray nums As Integer()) As Integer Return nums.Sum() End Function
When calling a function
Dim total As Integer = Sum(4, 3, 2, 1)
total returns 10 . Other functions that you can perform on it include Max() , Min() , etc.
Dennys Henry
source share