Namespaces

A namespace helps you to divide and conquer the complexity of the object hierarchy.
The .NET Framework organises its classes into namespaces
examples SS


Avoid defining types in the global namespace
The same namesapce can exist in multiple files
It is possible to nest namespace declarations


A collection of logically related types
Namespaces can be nested
avoids name conflicts
can include dots to indicate a hierarchical structure


namespace Better1 
{
   namespace MyDataStructures
   {
      namespace MyArrays
      {
      }
   }
}

is the same as

namespace Better1.MyDataStructures.MyArrays 
{
}

Qualified names can be broken after a dot (.) if they are too long for a single line, as shown in the following example.



Default / Global Namespace

Any classes or code that is not explicitly added to an explicit namespace is contained in the global namespace



Everything is an object that derives from the root class System.Object


Microsoft.CSharp namespace

This namespace contains classes that support compilation and code generation using th C# language.


using Directive

If you are using several objects from the same namespace you can save typing by adding the necessary using directive to the top of your program


If you do not want to fully qualify your namespaces you can use the using directive.
This provides a way of importing a namespace so it does not have to be fully qualified.


The main use of the using directive is to be able to refer to types without having to fully qualify them all.

using System 


Using Alias Directive

This can be used to create an alias for a namespace or a type.
The right side of a using alias directive must always be fully qualified.

using Excel = Microsoft.Office.Interop.Excel 


Static Members

You often find yourself repeating the class name as a prefix for the static members.

using static System.Console; 
using static System.Math;
WriteLine("some text");
Sqrt(4);

instead of

using System.Console; 
using System.Math;
Console.WriteLine("some text")
Math.Sqrt(4);


Using Statement

The using directive is not to be confused with the Using Statement which is used for defining the scope of objects.


VB.Net - Syntax


Using Directive

Imports System 


Using Alias Directive

Imports Excel = Microsoft.Office.Excel 

VB.Net - My

Introduced in Visual Basic 2005.
The My feature provides easy and intuitive access to a number of .NET Framework classes, enabling the Visual Basic user to interact with the computer, application, settings, resources, and so on.
link - learn.microsoft.com/en-us/archive/msdn-magazine/2006/vs-2005-guided-tour/visual-basic-using-my-namespace-to-navigate-projects-and-net


Provides quick access to some of the most common features which are sometimes hard to find otherwise in the .NET Framework.
All the features in the My object namespace are available in the .NET framework class library.
It means that you might have to learn 2 different ways of accessing the same thing.
My namespace is aimed at making the common development tasks very easy to perform.
Be aware that using these shortcuts might not give you all the power or functionality that you would get by accessing them directly from the class library
Extremely VB centric and not really used by many C# developers.
Also with the My namespace, the code you write will be much easier to understand and maintain when a new developer looks at it for the first time.



Using My Objects

The My objects gives you quick access to application, system and user information without having to search through the .NET Framework libraries

My.Applicationapplication specific seetings
My.Application.Info.DirectoryPathSystem.Reflection.Assembly.GetExecutingAssembly
 System.Reflection.Assembly.Location
My.Application.Info.VersionSystem.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion
My.Computercomputer component, for example clipboard
My.ComputerName 
My.Computer.Clock.LocalTime 
My.Computer.ClipboardSystem.Windows.Forms.Clipboard
My.Computer.Clipboard.GetText 
My.Computer.FileSystem.SpecialDirectories.Desktop 
My.Computer.FileSystem.WriteAllText 
My.Computer.FileSystem.ReadAllText 
My.Computer.FileSystem.Drivesan enumeration of available drives
My.Computer.FileSystem.DirectoryExistschecks the presence of a directory
My.Computer.Registry.GetValue 
My.Computer.Info.AvailablePhysicalMemory 
My.Computer.Info.TotalPhysicalMemory 
My.Computer.Info.OSFullName 
My.Computer.Info.OSPlatform 
My.Computer.Info.OSVersion 
My.Resourcesresources within your solution
My.Resources.Resources.MyResource 
My.Settings 
My.Settings.MysettingProperties.Settings.Default.Mysetting
My.Settings.Save 
My.Usercurrent user information
My.User.InitializeWithWindowsUser 
My.Forms 
My.WebServicesprovides an instance of very web service currently references in your solution.



© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext