Getting Maximum value of 6 numbers

  • Thread starter Thread starter John Yatla
  • Start date Start date
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?
 
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
 
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
 
I think the way you are using will be faster if comparing with the Array
techniques, but obviously the code looks untidy. :)

weichung
 
Back
Top