哪个代码段会提供更好的性能?以下代码段是用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)