My goal is to add an unknown number of integer coordinates to a collection. While I can add these coordinates to this list List<int[]> coordList = new List<int[]>(); I cannot check if coordList.Contains(specifiedCoordinate).
This is what I have so far:
List<int[]> coordList = new List<int[]>();
coordList.Add(new int[] {1, 3});
coordList.Add(new int[] {3, 6});
bool contains = coordList.Contains(new int[]{1, 3})
Console.WriteLine(contains);
However, contains is always false even though I specify the same values that I add.
I have tried ArrayList as a possible alternative, but the results are the same as using List.
If there’s something I’m not understanding or if there’s an alternative, I’m all ears.
Thank you!
>Solution :
It seems like you want:
bool contains = coordList.Any(a => a.SequenceEqual(new int[]{1, 3}));
.Any and .SequenceEqual are extension methods provided by the System.Linq namespace. You may need to ensure that you have using System.Linq; at the top of your code file to make this work.