Max() function

  • Thread starter Thread starter John A Grandy
  • Start date Start date
J

John A Grandy

does .NET have a Max() function ?

something like

MyMaxValue = Max(Value1,Value2,Value3,Value4)
 
John A Grandy said:
does .NET have a Max() function ?

something like

MyMaxValue = Max(Value1,Value2,Value3,Value4)

You can have the IDE search for you. Press Ctrl+Shift+Alt+F12 to open the
"symbol search" window. It might be a different combination depending on
your keyboard settings. It's also available from the menu Edit ->
Search&Replace -> Search for symbol. Enter "max" (without quotation marks)
and press <enter>.
 
* "John A Grandy said:
does .NET have a Max() function ?

something like

MyMaxValue = Max(Value1,Value2,Value3,Value4)

You can build a function like this by using 'Math.Max' (compares two
values).
 
John,
..NET has System.Math.Max that will find the max of two numbers, you can
write a Max that accepts any number of numbers using a ParamArray parameter.

Something like:

' VS.NET 2003 syntax
Function Max(ByVal ParamArray values() as Integer) As Integer
Dim result As Integer = Integer.MinValue
For Each value As Integer In values
result = Math.Max(result, value)
Next
Return result
End Function

Of course you can overload the above function for other types, such as Long,
Short, Byte, Single, Double, Decimal.

When we get VS.NET 2004 (Whidbey) we can write the above using Generics
which means the compiler will automatically overload for us!

Hope this helps
Jay
 
Back
Top