The.NET framework pops up everywhere in computing these days – whether you're creating a websites using ASP.NET or designing a report using SQL Server Reporting Services, chances are that you'll have to come across the .NET framework . But … what is it? The key to understanding.NET is to understand namespaces , and this is best done by reference to the biological classification system.
How Biologist Classify Life (This IS Relevant, Honest!)
Linnaeus (a biologist) classified life in the following hierarchy.
Thus a human descendants to the Eukarya kingdom, Animalia phylum, Chordata class, Mammalia order, Primates family, Hominidae genus and Homo species. One way to understand this is to write it as:
The.NET Framework Works in the Same Way
Consider the color pink. This can be written in.NET as:
To put this another way, Pink belongs to the System kingdom, the Drawing phylum and the Color Class – except they're not called these things, but instead are called namespaces .
References and the IMPORTS Statement
Suppose that you want to color your textbox pink. A typical command to do this is:
me.txtBox.BackColor = System.Drawing.Color.Pink
Do you really have to type all this out every time that you want to color something? The answer is no, because you can reference the System.Drawing.Color namespace. To do this in Visual Basic, you would write:
at the top of your code: that way, you could use objects in the Color namespace without qualifying them. For example:
me.txtBox.BackColor = Pink
Another Example – Creating a Text Reader
A command in Visual Basic to create a streamreader (something which reads in a text file) is:
DIM sr As New System.IO.StreamReader
However, because the StreamReader class belongs in the System.IO namespace, we could instead write this as:
followed at some stage by
DIM sr As New StreamReader .
The.NET framework is really just a collection of classes (4000+ when I last looked) arranged in a sensible hierarchy.