What Are Namespaces?
Namespaces are groups of classes, structures, interfaces, enumerations, and delegates, organized in a logical hierarchy by function, that enable you to access the core functionality you need in your applications.
Note
The System namespace contains all the base types you learned about yesterday, such as Int16, Int32, Decimal, and Short.Each namespace in the FCL can contain multiple namespaces, or they can contain classes that expose properties and methods that you call in your applications. The namespaces within the FCL are grouped by the functionality they provide, which makes it very easy to find what you're looking for. It can be compared to a phone book, in which you look under B for bugs, and are led to exterminators, which helps you find all the information you need to squash all the bugs. Similarly, you look for common words in what a namespace offers, and you'll most likely find the information you need to implement the task you're trying to accomplish.To separate the top-level namespace from the second-level namespace from the class to the actual property or method, the FCL uses the . (period) notation to differentiate the hierarchy. For example, if you want to work with data, and you're using SQL Server, you'll find the System.Data.SqlClient namespace. In the System.Data.SqlClient namespace are the SqlDataReader class and the SqlDataAdapter class, among many others. When you reference these object in code, you use the following syntax:
Dim rdr as System.Data.SqlClient.SqlDataReader
System.Data.SqlClient.SqlDataReader rdr;
Week 1, you used the System.Web namespace, the System.Web.UI namespace, the System.Windows.Forms namespace, and the System.Windows.Forms.Design namespace. Each namespace gave you all the base functionality you needed to create ASP.NET and Windows Forms applications. Each time you referenced a form object, either on the Windows Form or the Web Form, you were referencing a type in one of the namespaces I just mentioned. So, you're using namespaces and their types to accomplish everything you need to do when developing .NET applications.There are a couple things to note about cthe naming conventions you use when working with namespaces:
- Namespaces supplied by Microsoft are prefixed with System or Microsoft (for example, Microsoft.VisualBasic and System.IO). The System prefix means the namespace has come from the .NET team at Microsoft, and the Microsoft prefix means the namespace has come from one of the product groups. An example is Microsoft.Office.Excel.
- Third-party namespaces are prefixed by the name of the company that distributes the namespace; for example, Infragistics.UltraWinGrid.
When you get to Day 14, "Components and .NET," you learn how to create your own namespaces when writing components. You also see how you can use your own naming convention to avoid name collision with other namespaces in the FCL or third parties.
• Table of Contents
• Index
Sams Teach Yourself Visual Studio® .NET 2003 in 21 Days
By
Jason Beres
Publisher
: Sams Publishing
Pub Date
: January 14, 2003
ISBN
: 0-672-32421-0
Pages
: 696
Sams Teach Yourself Visual Studio .NET in 21 Days will help developers that are new to application development and experienced developers understand how to use the .NET Framework and Visual Studio .NET to rapidly develop any type of computer application. The Visual Studio .NET development environment is the most comprehensive developer tool ever created, putting that together with the .NET Frameworks' Class Libraries, the developer has everything he or she needs to get up-to-speed on Microsoft's latest revolution in application development. This book will guide the developer through using the VS .NET IDE, the Visual Basic .NET and C# language, and the supporting tools available from Microsoft to create Windows and Web-based applications. The market is full of books that pretty much say the same thing, which is already available in the help files, the author of this book has written and deployed over a dozen successful applications using Visual Studio .NET and the .NET Framework. All of his expertise and experience is used to give you the most comprehensive title on using Visual Studio .NET.