I do have two arrays:
int[] oddArr = { 11, 9, ... };
int[] evenArr = {4, 2, 8, ... };
I want to check if every items from oddArr is greater than every items from evenArr then we should do some logic.
Like:
if(11 > 4 && 11 > 2 && 11 > 8 && 9 > 4 && 9 > 2 && 9 > 8 && ...)
I tried something like this:
for (int i = 0; i < oddArr.Length; i++)
{
for (int j = 0; j < evenArr.Length; j++)
{
if (oddArr[i] > evenArr[j])
{
}
}
}
I would think about the problem differently - for everything in oddArr
to be greater than everything in evenArr
, then the minimum of oddArr
has to be greater than the maximum of evenArr
:
if (oddArr.Min() > evenArr.Max())
(You'll need a using
directive for System.Linq
to bring in the Min
and max
extension methods.)
See more on this question at Stackoverflow