Understanding O.O.P. Documentation in .Net
By David M. Woods
Published October 13, 2006, 1:47 pm in Software.
Love.those.dots.
OOP, especially as implemented by .Net, uses dots (periods) in a plethora of places. They are used to separate namespaces from objects, objects from other objects, objects from members, classes from members, and may even occur in the middle of a namespace or assembly. They even can represent numerical decimal points!
The bad news is that it's sometimes difficult to tell just what the code elements on either side of a dot actually are.
However, we can generalize somewhat about dots. Whenever a dot appears in an expression, it basically means: the element to the right of the dot is a member of whatever everything to the left of the dot returns. So if the above was a real expression, then "those" would be a member of a class or object named "love", and "dots" would be a member of the class or object named "love.those". And if "love.those.dots" was the name of a class or object, then you could put yet another element after the final dot.
Assemblies and Namespaces
Classes and other available OOP objects are compiled into units called Assemblies. Before anything in an assembly can be used, it must be added to your project as a Reference.
.Net automatically adds a half-dozen or so commonly-used assemblies to most projects you create in the IDE. To view them, open the Solution Explorer and expand the "References" icon for your project. Note the small grey rectangle icon which represents an assembly.
If the assembly you wish to use is not there, you must add it. Right-click "Assemblies" in the solution explorer and select "Add a Reference". Follow the instructions in the resulting dialog box.
Any assembly added to any project in the currently open solution will display in the Object Browser. In the left pane, note that assemblies, represented by that same small grey icon, are at the highest level in the object hierarchy. By the same token, the ONLY assemblies that display in the Browser are referenced assemblies and projects that you create.
Assemblies consist of Namespaces, which are groups of classes and other objects. The icon for a namespace resembles a pair of curly braces. Namespaces and assemblies are easily confused; both have names which might include multiple words separated by dots.
A fully-qualified class name or object name is preference by its namespace, and a dot: MyNamespace.MyClassname
However, if classes and objects from a particular namespace are used frequently within a program, there is a shortcut available which precludes you from having to preface the class name with the namespace every time. It's called "including" a namespace. To include a namespace in a C# program file:
Using Namespace;
In VB:
Imports Namespace
The include commands must appear at the top of the program file, before any variable or object declarations. You can have multiple includes.
In C#, when you create a form or class module, .Net automatically inserts a half-dozen or so common namespace "Using" commands for you.
In VB, instead of automatically inserting "Imports" commands, the half-dozen or so most common namespaces are put into a collection on the project properties. Right-click the project in the Solution Explorer, select "Properties", and on the dialog box, click "Common Properties", then "Imports." Note that this set of Imports will apply to any form or class added to the project.

Make A Comment.