[Solved] Why C# allow this fun? ; ; ; ; [duplicate]


Because semicolon ; is a valid Empty Statement

8.3 The empty statement

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.

Execution of an empty statement simply transfers control to the end
point of the statement. Thus, the end point of an empty statement is
reachable if the empty statement is reachable.

Also see: Statements (C# Programming Guide) – MSDN

The empty statement consists of a single semicolon. It does nothing
and can be used in places where a statement is required but no action
needs to be performed.

EDIT:

webClient.DownloadFile("http://www.who.int/inf-new/dnldtxt/introductions.zip", ;;;;;;;;;;;;;;;;"");

But Why error shows in this line ?

well ; semicolon is a valid empty statement but that doesn’t mean that you can place that anywhere in your code. DownloadFile method expects two parameters , would you place any statement in it like:

webClient.DownloadFile("http://www.who.int/inf-new/dnldtxt/introductions.zip",
                                             Console.Write("Some Text");,  "");

Where Console.Write is a valid statement itself, but it can’t be used for parameter.

Why this code compiles:

private void install()
{
    http://www.stackoverflow.com
    return;
}

Because it is treating http: as a Labeled statements and anything after the colon is considered as part of label text. The above code will produce a warning

This label has not been referenced

9

solved Why C# allow this fun? ; ; ; ; [duplicate]