I'm trying to write a info provider class. I want to provide deep copy through Clone()
. So what I tried is:
public MyInfoClass Clone()
{
MyInfoClass temp = (MyInfoClass)this.MemberwiseClone();
foreach (MySystem sys in _mySystems)
{
temp.AddSys(sys);
}
return temp;
}
The collection is as follows. Whenever the collection has at least a object it throws the exception:
Collection was modified; enumeration operation may not execute.
private ObservableCollection<MySystem> _mySystems;
public ObservableCollection<MySystem> MySystems
{
get{ return _mySystems; }
}
I tried debugging and observed that temp.AddSys(sys)
executes successfully but on the next step the exception is thrown. Can you please help?