public class MyStuff : ICloneable
{
public int A {get;set;}
public int B {get;set;}
public object Clone()
{
MyStuff Copy = (MyStuff)MemberwiseClone();
return Copy;
}
}
Now lets assume i have an array of MyStuff
MyStuff[] MyStuffObjs = PopulateMyStuff();
What is the quickest/easiest way to create a clone of MyStuffObjs implementing the Clone method?
I know i can iterate through the collection and copy each one.
List<MyStuff> NewStuff = new List<MyStuff>();
foreach(var Stuff in MyStuffObjs)
{
NewStuff.Add(Stuff.Clone());
}
return NewStuff.ToArray();
Surely there is a better way?