Partager via


Type.GUID Property

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

Gets the GUID associated with the Type.

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

Syntax

'Declaration
Public MustOverride ReadOnly Property GUID As Guid
public abstract Guid GUID { get; }

Property Value

Type: System.Guid
The GUID associated with the Type.

Remarks

A GUID is associated with a type using the GuidAttribute attribute.

Examples

The following example creates the class MyClass1 with a public method, creates a Type object corresponding to MyClass1, and gets the Guid structure using the GUID property of the Type class.



Class Example

   Public Class MyClass1

      Public Sub MyMethod1()
      End Sub 'MyMethod1

   End Class

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' Get the type corresponding to the class MyClass.
      Dim myType As Type = GetType(MyClass1)
      ' Get the object of the Guid.
      Dim myGuid As Guid = CType(myType.GUID, Guid)
      outputBlock.Text &= ("The name of the class is " + myType.ToString()) & vbCrLf
      outputBlock.Text &= ("The ClassId of MyClass is " + myType.GUID.ToString()) & vbCrLf
   End Sub 'Main 
End Class 'MyGetTypeFromCLSID
using System;

class Example
{
   public class MyClass1
   {
      public void MyMethod1()
      {
      }
   }
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Get the type corresponding to the class MyClass.
      Type myType = typeof(MyClass1);
      // Get the object of the Guid.
      Guid myGuid = (Guid)myType.GUID;
      outputBlock.Text += "The name of the class is " + myType.ToString() + "\n";
      outputBlock.Text += "The ClassId of MyClass is " + myType.GUID + "\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.

See Also

Reference