Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

12.1 Variable categories > 12.1.2 Instance variables - Pg. 214

181 12 Variables Variables represent storage locations. Every variable has a type that determines what values can be stored in the variable. C# is a type-safe language, and the C# compiler guarantees that values stored in variables are always of the appropriate type. The value of a variable can be changed through assignment or through use of the ++ and - - operators. Aliasing Passing a variable as a reference parameter (§12.1.5) or an output parameter (§12.1.6) creates an alias of the variable. The value of a variable can also be changed through assignment to an alias or through use of the ++ and - - operators on an alias. A variable shall be definitely assigned (§12.3) before its value can be obtained. As described in the following subclauses, variables are either initially assigned or initially unas- signed. An initially assigned variable has a well-defined initial value and is always considered definitely assigned. An initially unassigned variable has no initial value. For an initially unas- signed variable to be considered definitely assigned at a certain location, an assignment to the variable shall occur in every possible execution path leading to that location. 12.1 Variable categories C# defines seven categories of variables: static variables, instance variables, array elements, value parameters, reference parameters, output parameters, and local variables. The subclauses that follow describe each of these categories. [Example: In the following code