Type.ToString Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Returns a String representing the name of the current Type.
Assembly: mscorlib (in mscorlib.dll)
This method returns the fully qualified common language runtime namespace and name for all primitive types. For example, the C# instruction, (long)0.Type().ToString() returns "System.Int64" instead of merely "Int64".
If the current Type represents a generic type, the type and its type arguments are qualified by namespace and by nested type, but not by assembly. If the current Type represents a type parameter in the definition of a generic type or generic method, this method returns the unqualified name of the type parameter.
This following example demonstrates a use of the Namespace and Module properties and the ToString method of Type.
Note: |
|---|
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8. |
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
Note: