Object Variables
In addition to storing values, a variable can refer to an object. You assign an object to a variable for the same reasons you assign any value to a variable:
- A variable name is often shorter and easier to remember than the full path of methods or properties necessary to access the object itself.
- Using a variable that refers to an object is more efficient than repeatedly accessing the object itself through the necessary methods or properties.
- You can change a variable to refer to other objects while your code is running.
In This Section
Discusses declaring object variables and choosing the class you declare them to be.
Describes how to assign objects to object variables, and combine assignments and declarations.
Related Sections
Describes how to specify variable names and characteristics, including which type of data the variable can contain.