Function MinMaxArray Learn programming Visual Basic (




Function MinMaxArray 7


Create a function named MinMaxArray, to return the minimum and maximum values stored in an array, using reference parameters:

float[] data={1.5f, 0.7f, 8.0f}
MinMaxArray(data, ref minimum, ref maximum);
(after that call, minimum would contain 0.7, and maximum would contain 8.0)


Imports System
Public Class exercise127
    Public Shared Sub MinMaxArray(ByVal number As Single(), ByRef min As Single, ByRef max As Single)
        max = number(0)
        min = number(0)

        For i As Integer = 1 To number.Length - 1
            If number(i) > max Then max = number(i)
            If number(i) < min Then min = number(i)
    End Sub

    Public Shared Sub Main(ByVal args As String())
        Dim data As Single() = {3.5F, 0.5F, 9, 0F}
        Dim min As Single = 0.0F
        Dim max As Single = 0.0F
        MinMaxArray(data, min, max)
        Console.WriteLine("Minimun: {0} - Maximun: {1}", min, max)
    End Sub
End Class