I am trying to remove an element from Collection but ended up with error
Collection was modified; enumeration operation may not execute.
What i am trying to achieve?
Check Student list count in Report collection.
If count is == 1 Than check null or empty for Student properties
If all true than delete Student from Report collection..
Here is my code
public void Create(StudentReport report)
{
ICollection<StudentReportDetails> student= report.Students;
if (student.Count == 1)
{
foreach (StudentReportDetails Studetails in student)
{
if (String.IsNullOrEmpty(Studetails.StudentNumber)&& String.IsNullOrEmpty(Studetails.Description) && String.IsNullOrEmpty(Studetails.Summary))
{
report.Students.Remove(Studetails);
}
}
}
}