|
-
Apr 26th, 2010, 11:24 PM
#1
Thread Starter
Addicted Member
Real quick array.min question
Hey guys,
Can I do this to find the lowest value in an array greater than zero?
Code:
Dim findLowest() As Integer = {right, left, backRight, backLeft}
Dim theMove As Integer = findLowest.Min > 0
Can't seem to find it on MSDN.
Thanks.
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
Apr 26th, 2010, 11:28 PM
#2
Thread Starter
Addicted Member
Re: Real quick array.min question
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?
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
Apr 26th, 2010, 11:33 PM
#3
Thread Starter
Addicted Member
Re: Real quick array.min question
I know that:
Code:
For i = 0 To findLowest.Length - 1
If findLowest(i) < theMove And findLowest(i) > 0 Then
findLowest(i) = theMove
End If
Next
works.
I just want to find a better case for when my array size isn't 3. Know what I mean.
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
Apr 26th, 2010, 11:34 PM
#4
Frenzied Member
Re: Real quick array.min question
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
-
Apr 27th, 2010, 12:02 AM
#5
Re: Real quick array.min question
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.
vb.net Code:
Dim numbers As Integer() = {-2, -1, 0, 1, 2} MessageBox.Show(numbers.Where(Function(n) n > 0).Min().ToString())
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.
-
Apr 27th, 2010, 10:20 PM
#6
Thread Starter
Addicted Member
Re: Real quick array.min question
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|