Collection was modified; enumeration operation may not execute in ArrayList [duplicate]

You are removing the item during a foreach, yes? Simply, you can’t. There are a few common options here: use List<T> and RemoveAll with a predicate iterate backwards by index, removing matching items for(int i = list.Count – 1; i >= 0; i–) { if({some test}) list.RemoveAt(i); } use foreach, and put matching items into … Read more

How do I iterate over an NSArray?

The generally-preferred code for 10.5+/iOS. for (id object in array) { // do something with object } This construct is used to enumerate objects in a collection which conforms to the NSFastEnumeration protocol. This approach has a speed advantage because it stores pointers to several objects (obtained via a single method call) in a buffer … Read more

Case objects vs Enumerations in Scala

One big difference is that Enumerations come with support for instantiating them from some name String. For example: object Currency extends Enumeration { val GBP = Value(“GBP”) val EUR = Value(“EUR”) //etc. } Then you can do: val ccy = Currency.withName(“EUR”) This is useful when wishing to persist enumerations (for example, to a database) or … Read more

The foreach identifier and closures

Edit: this all changes in C# 5, with a change to where the variable is defined (in the eyes of the compiler). From C# 5 onwards, they are the same. Before C#5 The second is safe; the first isn’t. With foreach, the variable is declared outside the loop – i.e. Foo f; while(iterator.MoveNext()) { f … Read more

tech