Hey guys,
Can I do this to find the lowest value in an array greater than zero?
Can't seem to find it on MSDN.Code:Dim findLowest() As Integer = {right, left, backRight, backLeft}
Dim theMove As Integer = findLowest.Min > 0
Thanks.
Printable View
Hey guys,
Can I do this to find the lowest value in an array greater than zero?
Can't seem to find it on MSDN.Code:Dim findLowest() As Integer = {right, left, backRight, backLeft}
Dim theMove As Integer = findLowest.Min > 0
Thanks.
ok quick test says that I can't.
Is there a way to execute that? I want the minimum number in the array greater than 0 without having to redim and remove values. Is that possible?
I know that:
works.Code:For i = 0 To findLowest.Length - 1
If findLowest(i) < theMove And findLowest(i) > 0 Then
findLowest(i) = theMove
End If
Next
I just want to find a better case for when my array size isn't 3. Know what I mean.
you can sort the array by using Array.Sort and get the first value from the array if the sort id ascending else last value in case of descending.
I dont have idea about using the array sort function , never used it. May be should should consult the documentation
The Min method isn't a member of the Array class. It's an extension method, declared in the Enumerable class and extending the IEnumerable interface, which the Array class implements. You can use it in conjunction with other such extension methods, e.g.Just be aware that Min will throw an exception for an empty list, so that code will choke if there are no values greater than 0.vb.net Code:
Dim numbers As Integer() = {-2, -1, 0, 1, 2} MessageBox.Show(numbers.Where(Function(n) n > 0).Min().ToString())
Hey thanks JM.