18.3. Scope


You will remember that in Visual Basic 2005 objects declared within methods are called local variables. They are local to the method, as opposed to belonging to the object, as member variables do.

Local variables of intrinsic types such as Integer are created on the "stack." The stack is a portion of memory that is allocated as methods are invoked and freed as methods end. When you start a method, all the local variables are created on the stack. When the method ends, all the local variables are destroyed.

These variables are referred to as local because they exist (and are visible) only during the lifetime of the method. They are said to have local scope . When the method ends, the variable goes out of scope and is destroyed.

.NET divides the world of types into value types and reference types. Value types are created on the stack. All the intrinsic types (Integer, Long, etc.) are value types and thus are created on the stack.

Classes, on the other hand, are reference types. Reference types are created on the heap.



Programming Visual Basic 2005
Programming Visual Basic 2005
ISBN: 0596009496
EAN: 2147483647
Year: 2006
Pages: 162
Authors: Jesse Liberty

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net