0

I have 2 arrays which I compare below.

int[] values = { 1, 2, 3, 4, etc };

int[,] limits = { { 1, 2 }, { 2, 5 }, { 2, 6 },etc };

I can compare all the elements of the array quite easily, or specific elements in the array if they are sequential to see if they all fall within the corresponding limits using the following code,

 if (Enumerable.Range(0, values.Length).All(x => values[x] >= limits[x, 0] && values[x] <= limits[x, 1]))
 {
    //Do something            
 };

However, If I wanted to check only specific, non sequentional indecies in the array, eg indexes 0,4,6 & 9 how can I do this ? Thank in advance.

1 Answer 1

5

Just replace Enumerable.Range with a collection of the indexes you want to check

new[] {0, 4, 6, 9}.All(x => values[x] >= limits[x, 0] && values[x] <= limits[x, 1])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.