I am using C#, .Net 4.0, and I want to do the simple task of duplicating an Item in a dictionary (with a different key obviously).
I am running into a few problems.
When I make the initial copy, I have no problems. When I change the value of the copy, the value of the original also changes. Why is this?
private void CopyItem(Guid newItemKey, Guid oldItemKey)
{
this.dictionary[newItemKey] = this.dictionary[oldItemKey];
this.dictionary[newItemKey].Id = newItemKey;
}
// this.dictionary[oldItemKey].Id is now equal to newItemKey... Why?
I have also tried:
private void CopyItem(Guid newItemKey, Guid oldItemKey)
{
var value = this.dictionary[oldItemKey];
value.Id = newItemKey;
this.dictionary[newItemKey] = value;
}
// this.dictionary[oldItemKey].Id is now equal to newItemKey... Why?
I still get the same result.