1

I have a list of int arrays.

How do I search for a specific int[]?

Example:

var listIntArray = new List<int[]>();

listIntArray.Add(new int[] { 1, 2, 3, 4, 5, 6 });

var array1 = new int[] { 1, 2, 3, 4, 5, 6 };
bool contains1 = listIntArray.Contains(array1);
//--> should be true

var array2 = new int[] { 4, 5, 6 };
bool contains2 = listIntArray.Contains(array2);
//--> should be false
1

1 Answer 1

2

You could do this with LINQ.

bool result = listIntArray.Any(arr => arr.SequenceEqual(array1));
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.