UnclePacky
UnclePacky

Reputation: 11

c# searching a list of integer arrays

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

Upvotes: 1

Views: 79

Answers (1)

Jesse de Wit
Jesse de Wit

Reputation: 4177

You could do this with LINQ.

bool result = listIntArray.Any(arr => arr.SequenceEqual(array1));

Upvotes: 2

Related Questions