C# foreach
for( int i = arrInt.Count - 1; i >=0; i-- )
{
int n = ( int ) arrInt[i];
if( n == 5 )
arrInt.RemoveAt( i ); // Remove data here
Debug.WriteLine( n.ToString() );
}
除了这两个地方外,foreach可以基本适用于任何循环,因此对于循环的编写要尽量使用foreach,因为它会使你的代码清晰简洁,又不失高效。
相关文章: