Greatest value in a array Learn programming Visual Basic (VB.net)

Lesson:

Functions


Exercise:

Greatest value in a array 23


Objetive:

Create a function which returns the greatest value stored in an array of real numbers which is specified as parameter:

float[] data={1.5f, 0.7f, 8.0f}
float max = Maximum(data);


Code:

Imports System
Public Class exercise118
    Private Shared Sub Main(ByVal args As String())
        Dim data As Single() = {1.5F, 0.7F, 8.0F}
        Dim max As Single = Maximum(data)
        Console.WriteLine(max)
    End Sub

    Private Shared Function Maximum(ByVal list As Single()) As Single
        Dim max As Single = -99999999.00F

        For i As Integer = 0 To list.Length - 1

            If i = 0 Then
                max = list(i)
            Else
                max = If(max < list(i), list(i), max)
            End If
        Next

        Return max
    End Function
End Class