Export (0) Print
Expand All

Naming Variables and Constants

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Naming conventions typically use a lowercase prefix or suffix to specify the variable's type and scope. The variable itself should have a meaningful name that describes what it is or what it does. Multiple-word names are concatenated, the first letter of each word is capitalized, and the underscore character is not used. If you used a variable-name template, it would be in the form prefixNoun or prefixNounVerb.

Constant names should also be descriptive names in the NOUN or NOUN_VERB format. Constant names are uppercase and use an underscore character to separate words. Although there is nothing technically wrong with adding characters to constant names to specify data type and scope, it is not done often. A constant is really the same thing as a variable in the sense that both are symbolic representations of data. The difference is that variables can change and constants remain the same.

Both variable and constant names can contain up to 255 characters; however, names that exceed 25 to 30 characters can become unwieldy. Besides, 25 or 30 characters should be plenty of room to provide descriptive names that clearly convey the purpose of the variable or constant.

See Also

Using a Naming Convention | Variable Names | Constant Names | Naming Objects and Controls | Naming Functions and Subroutines

Show:
© 2014 Microsoft