語言

Type.GUID 屬性

定義

會獲得與 Type. 相關聯的 GUID。

public:
 abstract property Guid GUID { Guid get(); };
public abstract Guid GUID { get; }
member this.GUID : Guid
Public MustOverride ReadOnly Property GUID As Guid

屬性值

與 Type相關聯的 GUID

實作

範例

以下範例以公開方法建立類別MyClass1,建立Type對應於 MyClass1的物件,並利用Guid類別GUID的特性取得結構。Type

using System;

class MyGetTypeFromCLSID
{
    public class MyClass1
    {
        public void MyMethod1()
        {
        }
    }
    public static void Main()
    {
        // Get the type corresponding to the class MyClass.
        Type myType = typeof(MyClass1);
        // Get the object of the Guid.
        Guid myGuid =(Guid) myType.GUID;
        Console.WriteLine("The name of the class is "+myType.ToString());
        Console.WriteLine("The ClassId of MyClass is "+myType.GUID);				
    }
}
type MyClass1() =
    member _.MyMethod1() = ()

// Get the type corresponding to the class MyClass.
let myType = typeof<MyClass1>
// Get the object of the Guid.
let myGuid = myType.GUID
printfn $"The name of the class is {myType}"
printfn $"The ClassId of MyClass is {myType.GUID}"
Class MyGetTypeFromCLSID

    Public Class MyClass1

        Public Sub MyMethod1()
        End Sub

    End Class

    Public Shared Sub Main()
        ' Get the type corresponding to the class MyClass.
        Dim myType As Type = GetType(MyClass1)
        ' Get the object of the Guid.
        Dim myGuid As Guid = myType.GUID
        Console.WriteLine(("The name of the class is " + myType.ToString()))
        Console.WriteLine(("The ClassId of MyClass is " + myType.GUID.ToString()))
    End Sub
End Class

備註

這個屬性會回傳一個 GUID,該 GUID 會與屬性 GuidAttribute 相關的類型相關聯。 若該屬性被省略,則會自動指派一個 GUID。

此屬性回傳的 GUID 通常用來將類型暴露給 COM。 它並非用於該類型的唯一識別碼。

適用於

另請參閱