13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10 Basic concepts• Each block or switch-block creates a separate declaration space for labels. Names are introduced intothis declaration space through labeled-statements, and the names are referenced through gotostatements.The label declaration space of a block includes any nested blocks. Thus, within a nestedblock it is not possible to declare a label with the same name as a label in an enclosing block.The textual order in which names are declared is generally of no significance. In particular, textual order isnot significant for the declaration and use of namespaces, constants, methods, properties, events, indexers,operators, instance constructors, destructors, static constructors, and types. Declaration order is significant inthe following ways:• Declaration order for field declarations and local variable declarations determines the order in whichtheir initializers (if any) are executed.• Local variables must be defined before they are used (§10.7).• Declaration order for enum member declarations (§21.3) is significant when constant-expression valuesare omitted.[Example: The declaration space of a namespace is “open ended”, and two namespace declarations with thesame fully qualified name contribute to the same declaration space. For examplenamespace Megacorp.Data{class Customer{…}}namespace Megacorp.Data{class Order}{}…The two namespace declarations above contribute to the same declaration space, in this case declaring twoclasses with the fully qualified names Megacorp.Data.Customer and Megacorp.Data.Order. Becausethe two declarations contribute to the same declaration space, it would have caused a compile-time error ifeach contained a declaration of a class with the same name. end example][Note: As specified above, the declaration space of a block includes any nested blocks. Thus, in thefollowing example, the F and G methods result in a compile-time error because the name i is declared in theouter block and cannot be redeclared in the inner block. However, the H and I methods are valid since thetwo i’s are declared in separate non-nested blocks.class A{void F() {int i = 0;if (true) {int i = 1;}}void G() {if (true) {int i = 0;}int i = 1;}71

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!