To deep copy a .net object
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
///
/// Deep copy for a serializable object
///
///
///
///
public static T DeepCopy(T obj)
{
using (MemoryStream stream = new MemoryStream())
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, obj);
stream.Position = 0;
return (T)formatter.Deserialize(stream);
}
}
Usage (my own actual code, working)
List giacenzaOrg = DataStruct.DeepCopy>(DS.giacenza);
where Pallet was defined as
[Serializable()]
public class Pallet
{
public string UdC;
...