469,902 Members | 1,949 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,902 developers. It's quick & easy.

Max() function

does .NET have a Max() function ?

something like

MyMaxValue = Max(Value1,Value2,Value3,Value4)
Nov 20 '05 #1
3 28190
"John A Grandy" <johnagrandy-at-yahoo.com> schrieb
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>.
--
Armin

Nov 20 '05 #2
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

"John A Grandy" <johnagrandy-at-yahoo.com> wrote in message
news:u%****************@TK2MSFTNGP12.phx.gbl...
does .NET have a Max() function ?

something like

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

Nov 20 '05 #3
* "John A Grandy" <johnagrandy-at-yahoo.com> scripsit:
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).

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by pankaj_wolfhunter | last post: by
3 posts views Thread by james.eacret | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.