At the top of my code (before constructor) I write:
String[] CAN = null;
This string array is updated in another function.
Later in my code I have this foreach loop:
foreach (String str in CAN)
{
if(str.Contains("18FA07FE"))
cmdResult = true;
else
cmdResult = false;
}
I have tried to debug, and at the line of the foreach statement I can see that the CAN string array has successfully been updated, and now contains 1211 elements.
So I don’t really know why it’s giving me this exception.
If the problem is only related to the code you’ve shown, and the code you’ve described, and it’s true that the array has elements, then the only possible explanation is that one of the elements in
CANis a null element, and thus it isn’t the foreach itself that throws the exception, but this line: