I am always wondering why you can create a new object of the SomeClass class in a for loop, but you cannot do the same in foreach .
Example below:
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 someone explain this scenario to me?
zajke source share