Cloning queue in c# -
i have following code:
queue<string> oldqueue = new queue<string>(); oldqueue.enqueue("one"); oldqueue.enqueue("two"); oldqueue.enqueue("three"); queue newqueue = oldqueue; string newstring = newqueue.dequeue();
the problem once dequeue item newqueue
, item dequeued oldqueue
. there way "clone" queue in way removing item 1 queue keep it's clone queue unchanged?
queue reference type, newqueue , oldqueue holds pointer same object. same ;-)
see answer how "deep cloning" using reflection: