在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 = 10
Dim b As Integer = 5
Dim maxValue As Integer = Math.Max(a, b)
Dim minValue As Integer = Math.Min(a, b)
Console.WriteLine("最大值: " & maxValue)
Console.WriteLine("最小值: " & minValue)
输出结果为:
最大值: 10
最小值: 5
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至 55@qq.com 举报,一经查实,本站将立刻删除。转转请注明出处:https://www.szhjjp.com/n/832015.html