Information Technology Reference
In-Depth Information
Labeled Statements
A labeled statement consists of an identifier, followed by a colon, followed by a statement. It has
the following form:
Identifier : Statement
A labeled statement is executed exactly as if the label were not there and consisted of just
the Statement part.
￿
Adding a label to a statement allows control to be transferred to the statement from
another part of the code.
￿
Labeled statements are only allowed inside blocks.
Labels
Labels have their own declaration space, so the identifier in a labeled statement can be any
valid identifier—including those that might be declared in an overlapping scope, such as local
variables or parameter names.
For example, the following code shows the valid use of a label with the same identifier as a
local variable:
{
int xyz = 0; // Variable xyz
...
xyz: Console.WriteLine("No problem."); // Label xyz
}
There are restrictions, however. The identifier cannot be either
￿
The same as another label identifier with an overlapping scope
￿A keyword
Search WWH ::




Custom Search