I have an array of int array. I want to check if one int array exist in the collection
var coll = new int[3][]
{
new[] {5, 5},
new[] {4, 2},
new[] {3, 4}
};
var valueToCheck = new int[] {4, 2};
if (coll.Contains(valueToCheck))
{
// My logic
}
but coll.Contains(valueToCheck) is returning false.
Can someone suggest what am i doing wrong here?
falseis because yourvalueToCheckis a different object instance than your original array of{4, 2}. Despite the fact that theintvalues inside the arrays are equal, the arrays themselves are not because you are asking whether that instance of yourvalueToCheckarray is contained bycoll. It is not.