Lesser value from list of values? Lowest, Least?

  • Thread starter Thread starter wildman
  • Start date Start date
W

wildman

If there a VB.NET function that would return the lesser value from a
list of values?

For example,

Least(1,2,3,4,5)

would return 1.
 
If there a VB.NET function that would return the lesser value from a
list of values?

For example,

Least(1,2,3,4,5)

would return 1.

You didn't mention which framework version you're using, so you might as
well use the traditional method: a bit of programming ;-)

min=maxPossibleValue
for each x in someList
if x<min then min=x
next

Simple, and everyone knows what you're doing.

If you wanted to get the lowest value in large lists frequently, it might be
worth creating a class with an Add method which updates the current lowest
value, and a Remove method which checks if it's worth re-checking the lowest
value.

You can .Sort an Array and then the first item in the Array would be the
minimum. Depending on what you're doing, this may or may not be the way you
want to go.

Next someone'll be asking if there's a VB.NET method to play Space Invaders
:-) (Yes, I /do/ know about that from elsewhere.)

Andrew
 
Thank you. Does anybody have a simple working example that will work
in asp.net/vb.net codebehind code?

Public Shared Function Min ( _
source As IEnumerable(Of Decimal) _
) As Decimal

Visual Basic (Usage)


Dim source As IEnumerable(Of Decimal)
Dim returnValue As Decimal

returnValue = source.Min()
 
Back
Top