Is double colon (;;) allowed in C # .net?

I accidentally put two full colons at the end of a statement when writing code. I was amazed that it didn't give any errors. I mean, what is the purpose of allowing double half-density? What does this actually mean, and how can it be useful with any particular programming method?

+3


source to share


2 answers


Because it ;

is just an empty statement, in other words, a null statement . This is usually useless, but perfectly acceptable.

This is used in loops where you want to repeat something but don't want to add the body of the loop. As shown in the following example:



for ( i = 0; i < 10; line[i++] = 0 )
 ;

      

In your case, however, the first semicolon is the end of the statement, the second is an empty statement. This is useless and will be ignored by the compiler.

+4


source


;;

is just the end of the statement followed by an empty statement. Just like Oracle supports null;

. And other platforms do the same.

Sometimes you don't want to take an action when you have to meet a spec, like in if

, while

etc.

if (SomeAction())
  ;
else
  SomethingElse();

      



Which, of course, should be written as:

if (!SomeAction())
  SomethingElse();

      

It is probably easier to maintain ;;

as the end of a statement after an empty statement as a whole than to maintain all the specific scenarios where you want to resolve it.

+2


source







All Articles