Why does C# allow {} code blocks without a preceding statement?

后端 未结 9 2208
半阙折子戏
半阙折子戏 2020-12-14 13:48

Why does C# allow code blocks without a preceding statement (e.g. if, else, for, while)?

void Main()
{
           


        
9条回答
  •  Happy的楠姐
    2020-12-14 14:17

    1Because...Its Maintain the Scope Area of the statement.. or Function, This is really useful for mane the large code..

    {
        {
            // Here this 'i' is we can use for this scope only and out side of this scope we can't get this 'i' variable.
    
            int i = 0;
        }
    
        {
            int i = 0;
        }
    }
    

    enter image description here

提交回复
热议问题