So I needed a method for deep cloning. I wanted one map list to be equal to another map list, but then I also wanted to change one of the clones.
I made a way to copy the list as follows:
public List<Card> Copy(List<Card> cards)
{
List<Card> clone = new List<Card>();
foreach (var card in cards)
{
clone.Add(card);
}
return clone;
}
and use it as follows:
_cards = new List<Card>();
_thrownCards = new List<Card>();
_cards = Copy(_thrownCards);
_thrownCards.Clear();
I don't test in C #, but for some reason my gut feelings tell me that my copy method can be simplified. Is there no other way so you can copy the list? I tried using MemberWiseClone , but it just created references to the same object, not cloning (maybe I misinterpreted the MemberWiseClone method).
Does anyone have a clue how easy it is to clone a list object?