C # does not allow the values of elements in the array or collection to be altered in the Foreach Loop (note: The value of the member is not affected), as the following code will not compile.
(in MyArray){x//error code because the value of the element was changed by the Console. WriteLine(x);}
If you want a custom data type to support a foreach loop, the type must implement the Ienumerable<t> interface, and there is an ienumerator<t> implementation for this list. In fact, at the bottom of. NET (Il language level),
(in list//x is of type T... }
Equivalent to the following code:
(= List. ) The type of GetEnumerator ()//iterator is ienumerator<t>(iterator. MoveNext(= iterator. Current()}}
It is just an equivalent descriptive form to make it easier for users to use.
C # does not allow changing the values of elements in an array or collection in a Foreach Loop (note: The value of a member is not affected)