Question by
nazamoresco · Apr 28, 2019 at 02:46 AM ·
function
LIST full itself with the last element after leaving a for loop
Thanks for reading my question.
Im coping the elements from a dictionary to my list but after it leaves a loop all the elements in my list are equal to the last one.
I use charPrefab as a array to storage the keys to access my dictionary(all the elements are not equal)
I use dic as the dictionary
myList is the list giving my the problem
myList = new List<type>();
for (int i = 0; i < charPrefab.Length; i++)
{
current.name = charPrefab[i].name;
current.value = dic[charPrefab[i].name];
myList.Add(current);
}
//In this point, all my elements in myList is equal to the last element
Example if charPrefab is equal to [0,1,2,3], after leaving the loop my list is equal to [3,3,3,3], Thanks for reading my question
Comment
Your answer
Follow this Question
Related Questions
Simple Question 2 Answers
Load Scene Unity by Application.LoadLevelAsync 0 Answers
Problem about finding script name 1 Answer
Calling a function from another script 0 Answers
List.FindIndex 1 Answer