for loops
以下の2つの出力が異なる出力を生成する理由を理解できる人はいますか?
私の目には同じですが、元Dictionary
のオブジェクトfor loop
はそのメンバーの 9 つすべてを出力しますが、Queue
オブジェクトfor loop
は最初の 5 つだけを出力します。
void test()
{
Dictionary<int, string> d = new Dictionary<int, string>();
d.Add(0, "http://example.com/1.html");
d.Add(1, "http://example.com/2.html");
d.Add(2, "http://example.com/3.html");
d.Add(3, "http://example.com/4.html");
d.Add(4, "http://example.com/5.html");
d.Add(5, "http://example.com/6.html");
d.Add(6, "http://example.com/7.html");
d.Add(7, "http://example.com/8.html");
d.Add(8, "http://example.com/9.html");
Queue<KeyValuePair<int, string>> requestQueue = new Queue<KeyValuePair<int, string>>();
// build queue
foreach (KeyValuePair<int, string> dictionaryListItem in d)
{
requestQueue.Enqueue(dictionaryListItem);
Console.WriteLine(dictionaryListItem.Value);
}
Console.WriteLine(" ");
for (int i = 0; i < requestQueue.Count; i++)
{
Console.WriteLine(requestQueue.Peek().Value);
requestQueue.Dequeue();
}
}