SharePoint: differences between SPListCollection and SPListItemCollection

Okay the topic might not be as accurate as possible but here is something that I bet almost every SharePoint developer has faced, but might now have had any second thoughts. Back in C# language “principles”, it is not possible to modify collection (List<>, ArrayList, so on) while enumerating it (basically comes exception that says so).

Now here is interesting part: SPListItemCollection allows to perform .Update() into it’s items without exception (and everything goes out fine). But when trying to do so for example SPListCollection, you’ll get the familiar error (altought error might be hidden in SharePoint Hive Logs or your own logging system) about modifying collection and enumeration not possible.

I thought to add this entry since I spoke with couple other SharePoint developers and found out that okay this is how things go but never had a second thought for the matter. I am sure that someone else can dig deeper into this and why this is so. And feel free to do so.

About Sakarih

I am SharePoint developer/architect from Finland and my blogposts are all about SharePoint 2007/2010/2013 stuff. There might be also something else posted.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s