Does C# allow double semicolon ; ; if so, are there any special ways?

后端 未结 7 1684
盖世英雄少女心
盖世英雄少女心 2020-11-29 12:18

I am writing a statement and it compiles, but the compiler [VS] never tells me that I put the semicolon two times.

This means in ASP.NET MVC 3

return         


        
7条回答
  •  萌比男神i
    2020-11-29 12:53

    C# compiler does not allow ;; between if and else without braces and compiler will throw error in the below case.

    if (condition == true)
                    ; ; 
                else
                    ;
    

    Compiler Error:

    Error   CS1513  } expected  and one warning "Possible mistaken empty statement"
    

    So if you remove one semicolon it will work perfectly(or you need to add braces).

提交回复
热议问题