To a VB .NET programmer, an assembly is similar to a traditional DLL or EXE file, except that it contains additional information, such as reference and type information (which in COM was often contained in a separate OLB or TLB file, called a type library). When a VB .NET application is compiled, the compiler creates an assembly for the target EXE or DLL.
In the .NET environment, namespaces are part of assemblies. An assembly can contain many namespaces, and namespaces can be nested.
For instance, the System namespace is the fundamental namespace in the .NET environment. This is not the time to go into details, but one example will be useful. The System namespace identifies the Array class (Microsoft likes to say that the namespace contains classes.) One of the members of the Array class is the Copy method, which copies a portion of one array to another array. Thus, we can write code such as the following:
To use an existing assembly in a VB .NET project, you must do two things:
To access a member of a namespace, you can use its fully qualified name. For example, to create an instance of the Timers class, which is found in the System.Timers namespace, you can use a code fragment like the following:
Since using fully qualified names tends to be relatively cumbersome, you can include an Imports statement at the beginning of a code file, before any references to variables or classes. Its syntax is:
where aliasname is an optional alias for the namespace, and namespace is its fully qualified name. For example, if you import the System.Timers namespace as follows:
you do not have to qualify a reference to the Timer class, which can be instantiated as follows:
In the event that there is a naming conflict (either two namespaces have identically named types, or a named type conflicts with a name in your project), you can specify an alias for the namespace, as follows:
and then instantiate a Timer object as follows:
If you're using the Visual Basic command-line compiler, you have to explicitly import the Microsoft.VisualBasic namespace, or your code will not compile. If you're using Visual Studio, VB's language elements are accessed automatically without your having to import the namespace.
VB.NET Related Interview Questions
|VB.NET Interview Questions||ASP.NET Interview Questions|
|ADO.Net Interview Questions||Windows Presentation Foundation(WPF) Interview Questions|
|Windows CE .NET Interview Questions||Dot Net Framework Interview Questions|
|Asp Dot Net Mvc 4 Interview Questions||Asp Dot Net Mvc Interview Questions|
Variables And Data Types
Introduction To Object-oriented Programming
The .net Framework: General Concepts
The .net Framework Class Library
Delegates And Events
Error Handling In Vb .net
The Language Reference
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.