What is the special case with the foreach loop that eliminates bounds checking?

前端 未结 5 1050
清酒与你
清酒与你 2020-12-16 07:02

What is the special case with the foreach/for loop that eliminates bounds checking? Also which bounds checking is it?

5条回答
  •  醉酒成梦
    2020-12-16 07:29

    What? I'm not sure if it is even possible to eliminate bounds checking in c#. If you want unmanaged code, then use:

    int[] array;
    fixed (int * i = array)
    {
     while (i++)
      Console.WriteLine("{0}", *i);
    }
    

    for example - it doesn't check bounds, and dies terribly. :-)

提交回复
热议问题