|
|
|
|
|
|
|
Author Rank :
|
|
|
Page Views :
|
1307
|
|
Downloads :
|
0
|
|
Rating :
|
Rate it
|
|
Level :
|
Beginner
|
|
|
HTML clipboardAssemblies are for physical scope and namespaces are for logical scope, so
namespaces can be expanded over assemblies but the converse is not possible.
The namespace keyword is used to declare a scope. This namespace scope lets you
organize code and gives you a way to create globally unique types.
Even if you do not explicitly declare one, a default namespace is created. This
unnamed namespace, sometimes called the global namespace, is present in every
file. Any identifier in the global namespace is available for use in a named
namespace.
Namespaces are hierarchical. They implicitly have public access, which you
cannot modify.
It is possible to define a namespace in two or more declarations. For example,
the code in Listing 5.37 defines both classes as part of namespace MyCompany.
Listing 5.37: NameSpace.VB, Namespaces Example
'
recurring namespaces
Namespace
MyCompany.Proj1
Class [MyClass]
End
Class
End
Namespace
Namespace
MyCompany.Proj1
Class MyClass1
End
Class
End
Namespace
'nested namespaces
Namespace
SomeNameSpace
Public Class
[MyClass]
Public
Shared Sub Main()
Nested.NestedNameSpaceClass.SayHello()
End Sub
End Class
Namespace Nested
' a nested namespace
Public
Class NestedNameSpaceClass
Public
Shared Sub
SayHello()
Console.WriteLine("Hello")
Console.ReadLine()
End Sub
End
Class
End
Namespace
End
Namespace
The code listing generates the screen output in Figure 5.8.
Figure 5.8: Screen Output from Listing 5.37
VB programs are organized using namespaces, which serve as both an internal
organization system for a program and an external organization system that is, a
way of presenting program elements that are exposed to other programs.
VB also enables the definition and use of aliases. Such aliases can be useful in
situations in which name collisions occur between two libraries, or when a few
types from a much larger namespace are being used. Listing 5.38 presents code
from the preceding example, rewritten to use aliases.
Listing 5.38: NameSpace Assignment Example
Imports
MessageSource = Microsoft.CSharp.Introduction.HelloMessage
Class
Hello
Private
Shared Sub Main()
Dim m As
New MessageSource()
System.Console.WriteLine(m.GetMessage())
End
Sub
End
Class
An assembly is everything that comprises a .NET application. It is the unit of
deployment for the Microsoft .NET framework and takes the form of an executable
(.exe) file or dynamic-link library (DLL). What makes assemblies different from
.exe files or DLLs in earlier versions of Windows is that assemblies contain
within them all the information that you would find in a type library along with
information about everything else that is necessary to use the application or
component.
One of the primary goals of assemblies is versioning. Specifically, assemblies
provide a means for developers to specify version rules between different
software components and to have those rules enforced at runtime.
Because assemblies are the building blocks of applications, they are the logical
point for specifying and enforcing version information. Each assembly has a
specific version number as part of its identity.
Conclusion
Hope this article would have helped you in understanding Namespaces and
Assemblies in VB.NET.
|
|
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post
Here.
|
|
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
|
|
|
|
|
|
|
|
|
|
|
|
|