Getting Maximum value of 6 numbers

J

John Yatla

Here is how I've done it.

intMAX = Math.Max(Math.Max(Math.Max(dr("NAQty"),
dr("CurrentNotRequiredYetQty")), Math.Max(dr("OutstandingQty"),
dr("SavedQty"))), Math.Max(dr("UnapprovedQty"), dr("UpdatedQty")))

Is there a better way?
 
C

Chris Hyde

John said:
Here is how I've done it.

intMAX = Math.Max(Math.Max(Math.Max(dr("NAQty"),
dr("CurrentNotRequiredYetQty")), Math.Max(dr("OutstandingQty"),
dr("SavedQty"))), Math.Max(dr("UnapprovedQty"), dr("UpdatedQty")))

Is there a better way?
I am not sure of performance metrics, but you could just put the numbers
into an array, and then use the Array.Sort method.

The highest number will then be in the LAST index position of the array
(index 5 for a 6 item array);

HTH...

Chris
 
L

Lowell Heddings

Alternatively, since you are obviously pulling these numbers from a
database, you could do the sort in the database.

The array method would probably work best though.

Lowell
 
W

weichung[MCSD,MCDBA]

I think the way you are using will be faster if comparing with the Array
techniques, but obviously the code looks untidy. :)

weichung
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top