Sams Teach Yourself .Net in 21 Days
- Table of Contents
- Copyright
- About the Author
- About the Technical Editor
- Acknowledgments
- We Want to Hear from You
- Introduction
- Week 1: At a Glance
- Day 1. Introduction to the Microsoft .NET Framework
- Day 2. Introduction to Visual Studio .NET
- Day 3. Writing Windows Forms Applications
- Day 4. Deploying Windows Forms Applications
- Day 5. Writing ASP.NET Applications
- Day 6. Deploying ASP.NET Applications
- Day 7. Exceptions, Debugging, and Tracing
- Week 1. In Review
- Week 2: At a Glance
- Day 8. Core Language Concepts in Visual Basic .NET and C#
- Day 9. Using Namespaces in .NET
- Day 10. Accessing Data with ADO.NET
- Day 11. Understanding Visual Database Tools
- Day 12. Accessing XML in .NET
- Day 13. XML Web Services in .NET
- Day 14. Components and .NET
- Week 2. In Review
- Week 3: At a Glance
- Day 15. Writing International Applications
- Day 16. Using Macros in Visual Studio .NET
- Day 17. Automating Visual Studio .NET
- Day 18. Using Crystal Reports
- Day 19. Understanding Microsoft Application Center Test
- Day 20. Using Visual SourceSafe
- Day 21. Object Role Modeling with Visio
- Week 3. In Review
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.
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;
All through 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.
Finding the Information You Need About Namespaces | Next Section

Account Sign In
View your cart