Home
Username:
Password:
Microsoft Visual Basic .NET Tutorials

NET Framework / Namespaces




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

Ok something that is new to .NET especially for VB people, is the concept of namespaces. Now name spaces provide a classification system for our classes. Let me give you an example. Let's say that Lauren creates a class called get total (GetTotal), and then Janet creates a class called get total. If I want to call each of these, and assuming they have very different functionalities inside these classes, how do I know which one to call. Well, what if I call Lauren.GetTotal and I call Janet.GetTotal. This way I can specifically go to the particular class that I want based on the namespace. So a few years ago we learnt how to use classes to organize our procedures. We organized our set procedures and our functions into groups called classes and gave them names. Name spaces do the same thing for classes, they organize our classes and give them unique names. Now to use a name space, I'll refer to my particular class by using name space dot class. And then I can also use the import statement at the very top of my code, if I put the word imports and put the name of my namespace, then I don't have to preface all of my classes with the namespace name; this will save me some typing, you know. And, I'll show you this in an example in just a few minutes. As a matter of fact let's go take a look at an example now. I've opened a console application in a .NET and I want to show you something, now first of all I haven't talked about it yet, but all the .NET applications have to have an entry point into a program. And this is the sub-procedure called main. So this is where our program starts running. Well I'm going to do something here, I'm going to go down and create a public class called mark. Ok and within that public class, I'm going to do a public sub called do something. And inside there, I'm just going to write something to the console called hello. And I can't type and talk at the same time. OK now notice that if I come up here and down, x as a new object or a new class called mark, notice I get to my 'do something' method here or sub-procedure. So it has now become a method of that instantiated object. Now I want to back up just a minute. And let's do something different here; now I want to come down here and do Public Class, Janet and Public Sub do something, and I'm going to do a console.WriteLine and say 'Hi'. OK and so Mark comes on Write line and do something says 'Hello'; Janet says 'Hi'. Now what happens if I want to run DoSomething? Ok I need to specify which particular class it is, OK and this is not a big problem right now because when I down it, notice I am either going to tell it Janet or Mark, right; so namespaces aren't going to help me a whole lot here. But let's try something a little different here. What if, if I tried to set up another class named Mark, notice I'm going to get a line that says Mark and Mark conflict in the namespace console application. And console application you notice here is the name of my project, so what I'm going to do is I'm going to put a namespace called NS1 and then I'm going to end that namespace right there. Ok, then I'm going to create a namespace NS2 and then I would end that namespace. Ok so now when I down x as a new, notice I can now tell it NS, yeah there it is. NS1 dot Mark not x gets do something and get typed; and notice I'm calling this particular Mark because I'm asking for NS1. Now what if, say what, let's leave this this way and let's call do something. Now dim y as new NS2, Mark and y as do something. Notice I've got two classes named Mark, two identical methods but you'll notice that this one is coming from this namespace in this class, this one is coming from this namespace in this class. So that's how we use namespaces. Now in the next video we are going to start to go on to the hood with.NET and talk about how DLL's went away.

Tutorial Information

Course: Microsoft Visual Basic .NET
Author: Mark Long
SKU: 33433
ISBN: 1932072349
Release Date: 2003-05-27
Duration: 6 hrs / 87 lessons
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available