- Home /
Some problem while Queue in foreach loop
Why its Log(10,10,10,0,0,0)Finally?
public Queue<float> Queue_List = new Queue<float>();
void Start(){
QQ.Enqueue(10);
QQ.Enqueue(10);
QQ.Enqueue(10);
foreach(var data in Queue_List){
Debug.Log(data);
}
}
tt.png
(22.0 kB)
Comment
Best Answer
Answer by Bunny83 · Oct 01, 2020 at 01:13 PM
Are you sure your QQ is the same as your Queue_List? You may should work on your variable names first. Next thing is when you print something in the console you should make the log distinguishable by printing out some context. Next thing is are there other scripts which might log something? Also is this script only attached to one object in the scene? Try this instead:
public Queue<float> Queue_List = new Queue<float>();
void Start()
{
Queue_List.Enqueue(10);
Queue_List.Enqueue(10);
Queue_List.Enqueue(10);
Debug.Log("queue count: " + Queue_List.Count);
foreach(var data in Queue_List)
{
Debug.Log("queue data: " + data, gameObject);
}
}
Try this and see what you get.
Your answer
![](https://koobas.hobune.stream/wayback/20220613012913im_/https://answers.unity.com/themes/thub/images/avi.jpg)