VB.NET - Cheat sheet to calculating sum



Cheat sheet to calculating sum

 Function CalcSum(ByVal ParamArray val() As Integer) As Double
        Dim sum As Double = 0
        For i As Integer = LBound(val) To UBound(val)
            sum += val(i)
        Next
        Return sum
    End Function

Calling the method

    Private Sub btnSum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'output :15
        MessageBox.Show(CalcSum(1, 2, 3, 4, 5))
        'output :19
        MessageBox.Show(CalcSum(4, 5, 10))
    End Sub

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.