I have always wonder why you can create new object of class 'SomeClass' in for loop, but you can't do the same in foreach loop.
The example is bellow:
SomeClass[] N = new SomeClass[10];
foreach (SomeClass i in N)
{
i = new SomeClass(); // Cannot assign to 'i' because it is a 'foreach iteration variable'
}
for (int i = 0; i < N.Length; i++)
{
N[i] = new SomeClass(); // this is ok
}
Can anyone explain me this scenario?