Namespaces - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Namespaces

Description:

Namespaces organize the objects defined in an assembly ... Solution Explorer - Project Name - References - Right Click - Add Reference ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 18
Provided by: kevins88
Category:

less

Transcript and Presenter's Notes

Title: Namespaces


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
Contains Classes
Math
Operating System
Data
Text
Decoder
StringBuilder
Encoder
DataRow
Class
5
Namespace Names
  • The name of a namespace is actually a list of
    names separated by periods.

System.Text
System
Math
Operating System
Data
Text
Decoder
StringBuilder
Encoder
DataRow
System.Data.DataRow
System.Text.StringBuilder
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 -gt Microsoft Developer Network -gt MSDN
    Library for Visual Studio .NET 2003
  • You can also find it online, but this is slower
  • 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
System
Math
Operating System
Data
Text
Decoder
StringBuilder
Encoder
DataRow
  • To use a class you must tell Visual Studio .NET
    where to find it.
  • Use the fully qualified namespace (The full name)
  • Dim x As System.Text.StringBuilder
  • Use an imports statement
  • Imports System.Text
  • Dim x As StringBuilder

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 -gt Project -gt
    Right Click -gt Properties -gt Common Properties -gt
    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 -gt Project Name -gt References
    -gt Right Click -gt 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 -gt Project Name -gt Right Click
    -gt Properties -gt Common Properties -gt General -gt
    Root Namespace

17
Demonstration
  • Creating a Namespace
Write a Comment
User Comments (0)
About PowerShow.com