Type.Namespace Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the namespace of the Type.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public MustOverride ReadOnly Property Namespace As String
public abstract string Namespace { get; }

Property Value

Type: System.String
The namespace of the Type; nulla null reference (Nothing in Visual Basic) if the current instance has no namespace, or represents a generic parameter.

Remarks

A namespace is a logical design-time naming convenience, used mainly to define scope in an application and organize classes and other types in a single hierarchical structure. From the viewpoint of the runtime, there are no namespaces.

If the current Type represents a constructed generic type, this property returns the namespace that contains the generic type definition. Similarly, if the current Type represents a generic parameter T, this property returns the namespace that contains the generic type definition that defines T.

If the current Type object represents a generic parameter, this property returns nulla null reference (Nothing in Visual Basic).

Examples

This following example demonstrates a use of the Namespace and Module properties and the ToString method of Type.

Namespace MyNamespace
   Class [MyClass]
   End Class '[MyClass]
End Namespace 'MyNamespace
Public Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Try
         Dim myType As Type = GetType(MyNamespace.MyClass)
         outputBlock.Text += String.Format(ControlChars.NewLine + "Printing the details of {0}." + ControlChars.NewLine, myType) & vbCrLf
         ' Get the namespace of the class Example.
         outputBlock.Text += String.Format("Namespace: {0}.", myType.Namespace) & vbCrLf
         ' Get the name of the module.
         outputBlock.Text += String.Format("Module: {0}.", myType.Module) & vbCrLf
         ' Get the fully qualified common language runtime namespace.
         outputBlock.Text += String.Format("Fully qualified type: {0}.", myType.ToString()) & vbCrLf
      Catch e As Exception
         outputBlock.Text &= "Exception: " + e.Message.ToString() & vbCrLf
      End Try
   End Sub 'Main
End Class 'Type_ToString_3
using System;
namespace MyNamespace
{
   class MyClass
   {
   }
}
public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      try
      {
         Type myType = typeof(MyNamespace.MyClass);
         outputBlock.Text += String.Format("\nPrinting the details of {0}.\n", myType) + "\n";
         // Get the namespace of the class Example.
         outputBlock.Text += String.Format("Namespace: {0}.", myType.Namespace) + "\n";
         // Get the name of the module.
         outputBlock.Text += String.Format("Module: {0}.", myType.Module) + "\n";
         // Get the fully qualified common language runtime namespace.
         outputBlock.Text += String.Format("Fully qualified type: {0}.", myType.ToString()) + "\n";
      }
      catch (Exception e)
      {
         outputBlock.Text += "Exception: " + e.Message + "\n";
      }
   }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.