Copying one list to another list

How do I take the contents of one list and copy that data into another list? I have a class which handles deck related things, such as building decks, loading files, etc. Now when I use Debug.Log here to list the contents of the lists, it works fine.

What I am having trouble with is taking the contents from the deck list, and placing it into a playerDeck/enemyDeck list. I don’t know if more of my code is needed to see what is happening, if it is I can provide it. Also maybe it is important, maybe not, but the list is a list of gameObjects.

deck.cs

public void AddToDeck(string[] myDeck)
{
	deck.Clear();
	foreach(string line in myDeck)
	{
		if(line == "0")
		{
			WarriorCard battleChariot = new WarriorCard("Battle Chariot", 1, 12, 1);
			deck.Add(battleChariot);
			Debug.Log(battleChariot.Name);
			Debug.Log(battleChariot.HP);
			Debug.Log(battleChariot.DMG);
		}
}

mainGame.cs

void BuildDeck(string file)
{
	if(m_state == GameState.PlayerTurn)
	{
		deckInstance.Load(file);
		deckInstance.Shuffle();
		playerDeck = deckInstance.deck;
		Debug.Log(playerDeck.battleChariot.Name);
/*deck is the list variable used within the deck class and I have a new instance within this class*/
	}
	else if(m_state == GameState.AITurn)
	{
		deckInstance.Load(file);
		deckInstance.Shuffle();
		aiDeck = deckInstance.deck;
	}
}

How about System.Array.Copy?

If you want to copy a generic list, see CopyTo.

Or you could just:

var listCopy = new List<Stuff>(originalList);

Notice that just copies the list contents - if it was holding reference types, it would just copy the references over, it won’t clone the items themselves.

i.e.

public class Enemy
{
   public float damage;
}

var list = new List<Enemy>();
list.Add(new Enemy() { damage = 100 });
list.Add(new Enemy() { damage = 50 });
list.Add(new Enemy() { damage = 25 });

var copy = new List<Enemy>(list);
list[0].damage = 123;
print(copy[0].damage); // 123!

I created a script how to copy a new List ( clone all items / support multi dimensions / layers )

You can use it to copy new list in 1 sec only ^ ^