Lesser value from list of values? Lowest, Least?

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.
 
A

Andrew Morton

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
 
W

wildman

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()
 

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,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top