By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,960 Members | 1,396 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,960 IT Pros & Developers. It's quick & easy.

Max() function

P: n/a
does .NET have a Max() function ?

something like

MyMaxValue = Max(Value1,Value2,Value3,Value4)
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a
* "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.