Supposing I have a List<int>
its easy to search for an integer, lets say 6
List<int> list = new List<int>(){1, 2, 3, 4, 5};
if(list.Contains(6))
Console.Write("6 exists");
but how would I search for a int[]
in a List<int[]>
List<int[]> example = new List<int[]>();
example.Add(new int[4]{0,1,2,3});
example.Add(new int[4]{10,11,12,13});
example.Add(new int[4]{20,21,22,23});
How to search for {0,1,2,3}
and also delete that index on list?
int[] toFind = new int[4]{0,1,2,3};
foreach (int[] item in list)
{
if(item.Length == toFind.Length)
{
bool found = false;
for(int i=0; i < item.Length;i++)
{
if(item[i] == toFind[i])
{
found = true;
}
else
{
found = false;
}
}
}
}
I was trying to first compare wanted item length with each item length, the compare each item on array. There must be a better way to do this...