Download presentation
Presentation is loading. Please wait.
Published byBrenda Copeland Modified over 9 years ago
1
Namespaces Tonga Institute of Higher Education
2
Introduction to Namespaces The.Net Framework provides many classes for doing different things File Input/Output Displaying Windows Database Connectivity Etc. Microsoft needed a way to organize the classes. They decided to use namespaces. It is like the address of a class.NET Framework Class Library – The entire collection of classes Microsoft made for.NET organized by namespaces
3
Namespace Fundamentals Namespaces organize the objects defined in an assembly Assemblies – Primary unit of deployment for.NET Applications Dynamic Link Library (.DLL) Executable (.EXE) Assemblies can contain multiple namespaces, which can in turn contain other namespaces Namespaces prevent ambiguity and simplify references when using class libraries
4
Namespace Structure Namespaces are arranged hierarchically. Each namespace has a position above or below another namespace You can have namespaces inside of namespaces System Math DecoderStringBuilder Encoder Data Operating System DataRow Text Class Contains Classes
5
System Math DecoderStringBuilder Encoder Data Operating System DataRow Text Namespace Names The name of a namespace is actually a list of names separated by periods. System.Data.DataRow System.Text.StringBuilder System.Text
6
Using Namespaces If you want to use a built-in.NET class, first look it up in the Microsoft Developer Network Library (MSDN) The MSDN Library is installed on your computer Start -> Microsoft Developer Network -> MSDN Library for Visual Studio.NET 2003 You can also find it online, but this is slower www.msdn.com www.msdn.com If you know the class you want to use, search for that class. Otherwise, search for the.NET Framework Class Library Reference
7
Demonstration.NET Framework Class Library Resources
8
Imports Statements 1 To use a class you must tell Visual Studio.NET where to find it. 1. Use the fully qualified namespace (The full name) Dim x As System.Text.StringBuilder 2. Use an imports statement Imports System.Text Dim x As StringBuilder System Math DecoderStringBuilder Encoder Data Operating System DataRow Text
9
Imports Statements 2 Typing a fully qualified namespace is a lot of work The Imports statement makes this easier The namespace that contains the class you use Does not need to be the full name
10
Demonstration Using Import Statements
11
Import Defaults Visual Basic.NET automatically imports a few namespaces To see these: Solution Explorer -> Project -> Right Click -> Properties -> Common Properties -> Imports
12
Demonstration Import Defaults
13
References Namespaces organize the objects defined in an assembly Assemblies – Primary unit of deployment for.NET Applications There are 2 kinds: Dynamic Link Library (.DLL) Executable (.EXE) Each project has a list of standard assemblies it references If you want to use a class inside an assembly that is not automatically included, you must add it To add a reference to an assembly: Solution Explorer -> Project Name -> References -> Right Click -> Add Reference Select an assembly from the list or browse for the assembly Standard assembly references
14
Demonstration Default References and Adding References
15
Creating a NameSpace If we write code and share it with others we can use a namespace to organize our code Others will import the namespace we created to use our code in their program
16
Creating a NameSpace If you want to make your own namespace to be used in other programs, define it. Solution Explorer -> Project Name -> Right Click -> Properties -> Common Properties -> General -> Root Namespace
17
Demonstration Creating a Namespace
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.