12.2. Implicit Typing

One of the significant aspects of the .NET Framework is the Common Type System, which was introduced in order to separate the concept of a data type from any specific language implementation. This system is used as the basis for all .NET languages, guaranteeing type safety (although VB.NET developers can elect to disable Option Strict and/or Option Explicit, which both reduces the level of static, or "compile-time," type verification and can lead to undesirable runtime behavior).

More recently there has been a move away from statically typed languages toward more dynamic languages where the type checking is done at runtime. While this can improve developer productivity and increase flexibility so that an application can evolve, it also increases the probability that unexpected errors will be introduced.

In a concerted effort to ensure that the .NET Framework remains as the platform of choice, it was necessary for both C# and VB.NET to incorporate some of the productivity features of these more dynamic languages. One such feature is the ability to infer type information based on variable usage. This is often referred to as type inferencing or implicit typing. In Figure 12-2 you can see that we have not defined the type of the variable bob, yet when we use the variable it is clearly defined as a Person object. As this is a compiler feature, we get the added benefit of IntelliSense, which indicates what methods, properties, and fields are accessible, as well ...

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.