哪个代码段会提供更好的性能?以下代码段是用C#编写的.
1.
for(int counter=0; counter<list.Count; counter++)
{
list[counter].DoSomething();
}
Run Code Online (Sandbox Code Playgroud)
2.
foreach(MyType current in list)
{
current.DoSomething();
}
Run Code Online (Sandbox Code Playgroud) 这是在C#中,我有一个类,我从其他人的DLL使用.它没有实现IEnumerable,但有两个传递IEnumerator的方法.有没有办法可以在这些上使用foreach循环.我正在使用的课程是密封的.