To make code more self-documenting (always an important goal) and to reduce the chance of programming errors, you need an easy way to determine the exact data type of a variable or the exact type of a referenced control in Visual C# code. Using Prefixes to Denote Data TypeTable 11.4 lists the prefixes of the common data types. Although you don't have to use prefixes, there are many advantages to be gained by doing so.
By the Way The prefix of obj should be reserved for when a specific prefix isn't available. The most common use of this prefix is when referencing automation libraries of other applications. Denoting Scope Using Variable PrefixesPrefixes are useful not only to denote data types, they also can be used to denote scope (see Table 11.5). In particularly large applications, a scope designator is almost a necessity. Again, Visual C# doesn't care whether you use prefixes, but consistently using prefixes benefits you as well as others who have to review your code.
Prefixes aren't just for variables. All standard objects (including forms and controls) can use a three-character prefix. There are simply too many controls and objects to list all the prefixes here, although you'll find that I use control prefixes throughout this book. |