SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If we foreach a object elements in loop, I want to add or delete before, or after some elements. How I can I do at the loop foreach. Please help.

share|improve this question
up vote 2 down vote accepted

Use for loop instead of foreach and use index to access the Items like:

for (int index=0; index < ItemsCollection.Count; index++)
    SPListItem item = ItemsCollection[index];

because if you delete an item from ForEach it will give an exception, since the collection is changed now!

share|improve this answer
And Maybe You know how to add the range to the ASP Calendar ? – Grzegorz Z Nov 13 '12 at 14:19
Range? What do you mean by range? – Arsalan Adam Khatri Nov 13 '12 at 14:45
The range between Date Sstat to Date Stop. Please help. – Grzegorz Z Nov 13 '12 at 22:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.