Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

1 Answer 1

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];
    item.Delete();
}

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
1  
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

 
discard

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.