是否有一些罕见的语言构造我没有遇到过(比如我最近学到的一些,有些是关于Stack Overflow)在C#中得到一个表示foreach循环当前迭代的值?
例如,我目前根据具体情况做这样的事情:
int i = 0;
foreach (Object o in collection)
{
// ...
i++;
}
Run Code Online (Sandbox Code Playgroud) 我已经在这里回答了许多问题.但究竟是什么意思呢?
var test = new Dictionary<int, string>();
test.Add(0, "zero");
test.Add(1, "one");
test.Add(2, "two");
test.Add(3, "three");
Assert(test.ElementAt(2).Value == "two");
Run Code Online (Sandbox Code Playgroud)
上面的代码似乎按预期工作.那么字典被认为是无序的?在什么情况下上面的代码会失败?