Contents tagged with LINQ

  • LINQ vs FOREACH vs FOR Loop Performance

    I made a blatantly stupid logic mistake the other day in a business logic layer method that I was writing and got the following exception: “Collection was modified; enumeration operation may not execute.” The problem what I was trying to remove an object from a collection while I was enumerating through it using a FOREACH statement. After I realized what I had done I solved the problem by populating a new collection with a little bit of LINQ.