Reputation: 555
Say I have two arrays of the same length. E.g.:
Dim a() As Integer = {1, 2, 3, 4, 5}
Dim b() As Integer = {10, 20, 30, 40, 50}
Now I want to check if all items in b
are greater than the corresponding items (same index) in a
:
For i As Integer = 0 To a.Length - 1
If b(i) <= a(i)
Return False
End If
Next
Return True
Is there a one-line solution for that? Maybe something using LINQ's All() method?
Upvotes: 0
Views: 70
Reputation: 11773
In case the arrays are of different size
Dim result As Boolean = a.Length = b.Length AndAlso Enumerable.Range(0, a.Length).All(Function(i As Integer) b(i) > a(i))
Upvotes: 1
Reputation: 9981
Here's a one-liner for you:
Dim result As Boolean = Enumerable.Range(0, a.Length).All(Function(i As Integer) b(i) > a(i))
Upvotes: 2