在VB中,可以使用Math类的Max和Min方法来求最大值和最小值。
例如,下面的代码演示了如何求一个整数数组的最大值和最小值:
Dim numbers() As Integer = {10, 5, 20, 15, 8}Dim maxValue As Integer = Math.Max(numbers)Dim minValue As Integer = Math.Min(numbers)Console.WriteLine("最大值: " & maxValue)Console.WriteLine("最小值: " & minValue)输出结果为:
最大值: 20最小值: 5另外,如果要求两个数的最大值和最小值,可以直接使用Math类的Max和Min方法:
Dim a As Integer = 10Dim b As Integer = 5Dim maxValue As Integer = Math.Max(a, b)Dim minValue As Integer = Math.Min(a, b)Console.WriteLine("最大值: " & maxValue)Console.WriteLine("最小值: " & minValue)输出结果为:
最大值: 10最小值: 5 
