Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does code with multiple semicolons compile?

Tags:

syntax

c#

I am just curious to know why this is allowed.

int i=0;;

I accidentaly typed that. But the program compiled. I noticed it after many days that I have typed ;;

After that I tried with different symbols like ~, !, : etc etc

Why is that not allowed where as first one is allowed.

Just curious to know.

like image 452
Sandeep Avatar asked Nov 29 '22 19:11

Sandeep


1 Answers

You have typed an empty statement:

int i=0; // that's one statement
; // that's another

It's legal for an statement in C# to have no body.

From section 8.3 of the C# Language Specification:

An empty-statement does nothing.

empty-statement:
;
An empty statement is used when there are no operations to perform in a context where a statement is required.

like image 145
Michael Petrotta Avatar answered Dec 14 '22 12:12

Michael Petrotta