Home > Net >  C#
C#

Time:01-22

Foreac take an array of original cannot change inside the

CodePudding user response:

Can't modify, delete, add

CodePudding user response:

To avoid this problem with a for loop

CodePudding user response:

For modify the collection in the foreach creates confusion, so in the foreach banned modify collection, otherwise you will quote invalid operation error,
Says the used for above is allowed, but if used for, the operation process, must pay attention to the index, the change of the elements,

CodePudding user response:

After cloning process

CodePudding user response:

Yes, for internal use foreach iterator that can maintain a logo, judge whether the source collection changes, once changed it complains "collection has been amended" error, were used for loop traverse the variable set,

CodePudding user response:

# 5 is the solution, not here

CodePudding user response:

If you want to change can bring you traverse a collection of plus. ToList ();

CodePudding user response:

Foreach is unsafe, considering safety can be used for.

CopyTo, Clone, ToList can all,