- Home /
Reading all data in the list with duplicate data inside
I am having a problem reading all the list using for loop with duplicate data inside the list.
This is my code:
List<string> MyList= new List<string>();
void Start () {
MyList.Add("SampTable");
MyList.Add("Respawn");
MyList.Add("SampTable");
}
public void ReadList()
{
int TagNum = MyList.Count;
for(int i = 0; i < TagNum; i++)
{
Debug.Log(TagNum);
Debug.Log(MyList[i]);
}
}
However the output is always
3
SampTable
Respawn
I want the output like
3
SampTable
Respawn
SampTable
Answer by SuperScience · Oct 07, 2018 at 08:18 AM
Hi Kerboy,
I think that you just have message stacking turned on.
Is there a number off to the far right with a 2 next to SampTable? If so - that means that you got 2 duplicate output messages from the same line, and to conserve space it collapses them and gives you a count.
There's a tab above the output console that says "Collapse". Uncheck it, and it should expand your outputs
Your answer
![](https://koobas.hobune.stream/wayback/20220612175919im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can you do calculations on two lists? 1 Answer
How do i convert this code snippet to a list? 1 Answer
Undo/back system using a List/Array 2 Answers
How to return index of List element? 1 Answer
How to modify array values? 1 Answer