Last time interview, I got this questions for test.
I would like to know which answer is correct.
Q: Assume you have a list "ABC" which contains structures of "XYZ". "ABC" has 10 "XYZ" objects in.
Each structure has only three integers (x,y and z). all x and y have been assigned values and z is zero.
there is a code snippet as shown below.
foreach(XYZ obj in ABC)
{
obj.z = obj.x;
obj.z = obj.z * obj.y;
}
what value you would expect to see in the structure objects in "ABC" after this ?
1) All z values in the structure Z will be zero
2) All z values in the structure Z will be equal to value x
3) Only the first structure in the list "ABC" will have z values equal to x*y
4) All z values in the structure Z will be equal to value x * y