Saturday, January 8, 2011

Something The C# Compiler Will Let You Do

While writing unit tests, I shoot myself in the foot trying the re use an already declared int.
I am surprise that the C# compiler will let you do this.
The result is that we will only loop once in the first loop.

        static  void  LoopIssue()
         {             
             for  (int  i = 0; i < 5; i++){
 
                 Console .WriteLine("i:{0}" , i);
 
                 for  (i = 0; i < 10; i++){

                     Console .WriteLine("   i:{0}" , i);
                 }
             }            
         }

No comments:

Post a Comment