Sunday, October 20, 2013

C# copy a Queue so initial values remain.

public static T DeepClone<T>(T obj)
{
    using (var ms = new MemoryStream())
    {
        var formatter = new BinaryFormatter();
        formatter.Serialize(ms, obj); ms.Position = 0;
       
        return (T) formatter.Deserialize(ms);
    }
}

//The class object must be marked as Serializable.

No comments: