Home arrow ASP.NET arrow Page 3 - Prerequisites For .NET Programming
ASP.NET

Prerequisites For .NET Programming


The .NET framework and all of its languages are quite large, and can take quite a while to learn in their entirety. If you've never programmed in an object-orientated language before, then you should know a couple of things before jumping into .NET programming. In this article, James will provide you with primers for the object-orientated paradigm, as well as the concept of a namespace.

Author Info:
By: James Yang
Rating: 5 stars5 stars5 stars5 stars5 stars / 20
January 06, 2002
TABLE OF CONTENTS:
  1. · Prerequisites For .NET Programming
  2. · Object-orientated programming
  3. · Namespaces
  4. · Conclusion

print this article
SEARCH DEVARTICLES

Prerequisites For .NET Programming - Namespaces
(Page 3 of 4 )

As with C++, namespaces are a vital part of .NET languages. You can think of a namespace as a "virtual container" for classes, functions and variables, which encapsulates them into a uniquely identifiable region. Namespaces separate variables into physical scopes, which reduces variable naming ambiguities. The pseudo code for a namespace is shown below:

Namespace ns1

{

variable x

Namespace ns2

{

variable y

}

}


As you can see, namespaces are hierarchical, meaning that several namespaces can be declared (and used) within a "parent" namespace. To refer to a nested namespace, you need to reference it using its parent Id first, followed by the dot operator ".", and then its actual namespace name.

For example, if you wanted to refer to the "sqlConnection" class in the "Data" level two namespace (second in the hierarchy) to create a new instance of that object, then you would do so like this:

System.Data.sqlConnection myConn = new System.Data.sqlConnection();

See how the dot operator separates each new namespace hierarchy? If we ran this line of C# code, then the "myConn" object would now contain a new instance of the System.Data.sqlConnection class.

Here is a simple example of using namespaces in both VB.NET and C#:

VB.NET:

Namespace Computer

Class IBM

'Class methods go here

End Class

End Namespace


C#:

namespace Computer

{

class IBM

{

// Class methods go here

}

}


As mentioned above, namespaces can be arranged in a hierarchical format. We can create nested namespaces in both VB.NET and C#:

VB.NET:

Namespace Computer

Namespace Desktop

Class IBM

'Class methods go here

End Class

End Namespace

Namespace Server

Class MainFrame

Public Function ShowMainFrame

'Code for function goes here

End Function

End Class

End Namespace

End Namespace


C#:

namespace Computer

{

namespace Desktop

{

class IBM

{

// Class methods go here

}

}

namespace Server

{

class MainFrame

{

public void ShowMainFrame()

{

// Code for function goes here

}

}

}

}


Namespaces are very simple to create in both VB.NET and C#. In VB.NET, we use the "Namespace namespace_name ... End Namespace" syntax, while in C#, we use the "namespace namespace_name {}" syntax. As you'll see in future articles, all classes in both VB.NET and C# are encapsulated into namespaces.
blog comments powered by Disqus
ASP.NET ARTICLES

- How Caching Means More Ca-ching, Part 2
- How Caching Means More Ca-ching, Part 1
- Reading a Delimited File Using ASP.Net and V...
- What is .Net and Where is ASP.NET?
- An Object Driven Interface with .Net
- Create Your Own Guestbook In ASP.NET
- HTTP File Download Without User Interaction ...
- Dynamically Using Methods in ASP.NET
- Changing the Page Size Interactively in a Da...
- XML Serialization in ASP.NET
- Using Objects in ASP.NET: Part 1/2
- IE Web Controls in VB.NET
- Class Frameworks in VB .NET
- Cryptographic Objects in C#: Part 1
- Sample Chapter: Pure ASP.Net

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials