- Home /
copy an list in c#
List <GameObject>master //with length 26
List<GameObject> temporary //with length 26
how to copy from master list game object to temporary list in c#.
One more question how to remove the game object from an array with out destroying the removed game object using the array index.
Are you still around? Only you can accept an answer and mark the question as "answered".
Answer by Shrandis · Nov 30, 2012 at 04:21 PM
List<GameObject> temporary = new List<GameObject>(master);
Please note that there are many ways to copy from one list to another, including simple foreach, Linq extension methods and expressions. But this one is, I think, the simplest one to use.
About your second question, if you're going to add/remove elements dynamically, use a List instead. You can easily use `myList.Remove(gameObject)`, or `myList.RemoveAt(index)`
Please do not forget to click the checkmark & thumbs up icons near the answer if it solves your problem.
Thanks! If you don't do it this way, it creates a reference to your original list and can create very strange results when accessing the list.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Copy From Array to List without reference [C#] 2 Answers
How to make a deep copy instead of a shallow one? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers