If I have a loop such as below:
foreach (string pass in new string[] { "pass1", "pass2", "pass3" })
{
x = pass; //etc
}
does the anonymous string array get created once initially, or recreated once for each pass?
I believe the former, but collegues are convinced this is a bug waiting to happen because they say every iteration of the foreach loop results in a new string array being created.
The VS Disassembly code suggests I am right, but I want to be sure.
The reason we are looking at this is to try to understand a mysterious bug that reports that a collection has been changed whilst iterating over it.
DateTime
value for example instead of strings and inspect the members in each iteration.new string[] { "pass1", "pass" + i++, "pass3" }