Guid 構造体

定義

グローバル一意識別子 (GUID) を表します。

public value class Guid : IComparable, IComparable<Guid>, IEquatable<Guid>, IFormattable
public value class Guid : IComparable, IComparable<Guid>, IEquatable<Guid>, ISpanFormattable
public value class Guid : IComparable, IComparable<Guid>, IEquatable<Guid>, IParsable<Guid>, ISpanFormattable, ISpanParsable<Guid>
public value class Guid : IComparable, IFormattable
public struct Guid : IComparable, IComparable<Guid>, IEquatable<Guid>, IFormattable
public readonly struct Guid : IComparable, IComparable<Guid>, IEquatable<Guid>, ISpanFormattable
public readonly struct Guid : IComparable, IComparable<Guid>, IEquatable<Guid>, IParsable<Guid>, ISpanFormattable, ISpanParsable<Guid>
[System.Serializable]
public struct Guid : IComparable, IFormattable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct Guid : IComparable, IComparable<Guid>, IEquatable<Guid>, IFormattable
type Guid = struct
    interface IFormattable
type Guid = struct
    interface ISpanFormattable
    interface IFormattable
type Guid = struct
    interface IFormattable
    interface IParsable<Guid>
    interface ISpanFormattable
    interface ISpanParsable<Guid>
[<System.Serializable>]
type Guid = struct
    interface IFormattable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Guid = struct
    interface IFormattable
Public Structure Guid
Implements IComparable, IComparable(Of Guid), IEquatable(Of Guid), IFormattable
Public Structure Guid
Implements IComparable, IComparable(Of Guid), IEquatable(Of Guid), ISpanFormattable
Public Structure Guid
Implements IComparable, IComparable(Of Guid), IEquatable(Of Guid), IParsable(Of Guid), ISpanFormattable, ISpanParsable(Of Guid)
Public Structure Guid
Implements IComparable, IFormattable
継承
属性
実装

次の例では、 クラスを System.Runtime.InteropServices.GuidAttribute 使用して、インターフェイスとユーザー定義クラスに GUID を割り当てます。 メソッドを呼び出して GUID の値を GetCustomAttribute 取得し、他の 2 つの GUID と比較して、それらが等しいかどうかを判断します。

using namespace System;
using namespace System::Runtime::InteropServices;

// Guid for the interface IMyInterface.
[Guid("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4")]
public interface class IMyInterface
{
public:
   void MyMethod();
};


// Guid for the coclass MyTestClass.
[Guid("936DA01F-9ABD-4d9d-80C7-02AF85C822A8")]
public ref class MyTestClass: public IMyInterface
{
public:
   virtual void MyMethod(){}
};

int main()
{
   Attribute^ IMyInterfaceAttribute = Attribute::GetCustomAttribute( IMyInterface::typeid, GuidAttribute::typeid );

   // The Value property of GuidAttribute returns a string. 
   System::Console::WriteLine( String::Concat(  "IMyInterface Attribute: ", (dynamic_cast<GuidAttribute^>(IMyInterfaceAttribute))->Value ) );

   // Using the string to create a guid.
   Guid myGuid1 = Guid(dynamic_cast<GuidAttribute^>(IMyInterfaceAttribute)->Value);

   // Using a byte array to create a guid.
   Guid myGuid2 = Guid(myGuid1.ToByteArray());

   // Equals is overridden to perform a value comparison.
   if ( myGuid1.Equals( myGuid2 ) )
      System::Console::WriteLine(  "myGuid1 equals myGuid2" );
   else
      System::Console::WriteLine(  "myGuid1 not equals myGuid2" );

   // Equality operator can also be used to determine if two guids have same value.
   if ( myGuid1 == myGuid2 )
      System::Console::WriteLine(  "myGuid1 == myGuid2" );
   else
      System::Console::WriteLine(  "myGuid1 != myGuid2" );
}
// The example displays the following output:
//       IMyInterface Attribute: F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4
//       myGuid1 equals myGuid2
//       myGuid1 == myGuid2
using System;
using System.Runtime.InteropServices;

// Guid for the interface IMyInterface.
[Guid("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4")]
interface IMyInterface
{
    void MyMethod();
}

// Guid for the coclass MyTestClass.
[Guid("936DA01F-9ABD-4d9d-80C7-02AF85C822A8")]
public class MyTestClass : IMyInterface
{
    public void MyMethod() {}

    public static void Main( string []args )
    {
        GuidAttribute IMyInterfaceAttribute = (GuidAttribute) Attribute.GetCustomAttribute(typeof(IMyInterface), typeof(GuidAttribute));

        System.Console.WriteLine("IMyInterface Attribute: " + IMyInterfaceAttribute.Value );

        // Use the string to create a guid.
        Guid myGuid1 = new Guid(IMyInterfaceAttribute.Value );
        // Use a byte array to create a guid.
        Guid myGuid2 = new Guid(myGuid1.ToByteArray());

        if (myGuid1.Equals(myGuid2))
            System.Console.WriteLine("myGuid1 equals myGuid2");
        else
            System.Console.WriteLine("myGuid1 does not equal myGuid2" );

        // Equality operator can also be used to determine if two guids have same value.
        if ( myGuid1 == myGuid2 )
            System.Console.WriteLine( "myGuid1 == myGuid2" );
        else
            System.Console.WriteLine( "myGuid1 != myGuid2" );
    }
}
// The example displays the following output:
//       IMyInterface Attribute: F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4
//       myGuid1 equals myGuid2
//       myGuid1 == myGuid2
open System
open System.Runtime.InteropServices

// Guid for the interface IMyInterface.
[<Guid "F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4">]
type IMyInterface =
    abstract MyMethod: unit -> unit

// Guid for the coclass MyTestClass.
[<Guid "936DA01F-9ABD-4d9d-80C7-02AF85C822A8">]
type MyTestClass() =
    interface IMyInterface with
        member _.MyMethod() = ()

let IMyInterfaceAttribute = 
    Attribute.GetCustomAttribute(typeof<IMyInterface>, typeof<GuidAttribute>) :?> GuidAttribute

printfn $"IMyInterface Attribute: {IMyInterfaceAttribute.Value}"

// Use the string to create a guid.
let myGuid1 = Guid IMyInterfaceAttribute.Value
// Use a byte array to create a guid.
let myGuid2 = Guid(myGuid1.ToByteArray())

if myGuid1.Equals myGuid2 then
    printfn "myGuid1 equals myGuid2"
else
    printfn "myGuid1 does not equal myGuid2"

// Equality operator can also be used to determine if two guids have same value.
if myGuid1 = myGuid2 then
    printfn "myGuid1 == myGuid2"
else
    printfn "myGuid1 <> myGuid2"

// The example displays the following output:
//       IMyInterface Attribute: F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4
//       myGuid1 equals myGuid2
//       myGuid1 == myGuid2
Imports System.Runtime.InteropServices

' Guid for the interface IMyInterface.
<Guid("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4")> _
Interface IMyInterface
    Sub MyMethod()
End Interface

' Guid for the coclass MyTestClass.
<Guid("936DA01F-9ABD-4d9d-80C7-02AF85C822A8")> _
Public Class MyTestClass
    Implements IMyInterface

    Public Sub MyMethod() Implements IMyInterface.MyMethod
    End Sub

    Public Shared Sub Main()
        Dim IMyInterfaceAttribute As GuidAttribute = CType(Attribute.GetCustomAttribute(GetType(IMyInterface), GetType(GuidAttribute)),
                                                           GuidAttribute)

        Console.WriteLine("IMyInterface Attribute: " + IMyInterfaceAttribute.Value)

        ' Use the string to create a guid.
        Dim myGuid1 As New Guid(IMyInterfaceAttribute.Value)
        ' Use a byte array to create a guid.
        Dim myGuid2 As New Guid(myGuid1.ToByteArray())

        If myGuid1.Equals(myGuid2) Then
            Console.WriteLine("myGuid1 equals myGuid2")
        Else
            Console.WriteLine("myGuid1 does not equal myGuid2")
        End If 

        ' The equality operator can also be used to determine if two guids have same value.
        If myGuid1.ToString() = myGuid2.ToString() Then
            Console.WriteLine("myGuid1 == myGuid2")
        Else
            Console.WriteLine("myGuid1 != myGuid2")
        End If
    End Sub
End Class
' The example displays the following output:
'       IMyInterface Attribute: F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4
'       myGuid1 equals myGuid2
'       myGuid1 == myGuid2

GuidAttribute属性は通常、COM に型を公開するためにアプリケーションで使用されることに注意してください。 この例をコンパイルすると、生成された アセンブリでアセンブリ登録ツール (Regasm.exe) を実行して、レジストリ (.reg) ファイルとタイプ ライブラリ (.tlb) ファイルを作成できます。 .reg ファイルを使用してレジストリにコクラスを登録でき、.tlb ファイルは COM 相互運用のためのメタデータを提供できます。

注釈

GUID は 128 ビットの整数 (16 バイト) であり、一意の識別子が必要な場合は常にすべてのコンピューターとネットワークで使用できます。 このような識別子は、重複する可能性が非常に低くなります。

コンストラクター

Guid(Byte[])

指定したバイト配列を使用して、Guid 構造体の新しいインスタンスを初期化します。

Guid(Int32, Int16, Int16, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte)

指定した整数とバイトを使用して、Guid 構造体の新しいインスタンスを初期化します。

Guid(Int32, Int16, Int16, Byte[])

指定した整数とバイト配列を使用して、Guid 構造体の新しいインスタンスを初期化します。

Guid(ReadOnlySpan<Byte>)

指定した読み取り専用のバイト スパンで表される値を使用して、Guid 構造体の新しいインスタンスを初期化します。

Guid(String)

指定した文字列で表される値を使用して、Guid 構造体の新しいインスタンスを初期化します。

Guid(UInt32, UInt16, UInt16, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte)

指定した符号なし整数とバイトを使用して、Guid 構造体の新しいインスタンスを初期化します。

フィールド

Empty

値がすべて 0 である Guid 構造体の読み取り専用インスタンス。

メソッド

CompareTo(Guid)

指定した Guid オブジェクトとこのインスタンスを比較し、これらの相対値を示す値を返します。

CompareTo(Object)

指定したオブジェクトとこのインスタンスを比較し、これらの相対値を示す値を返します。

Equals(Guid)

このインスタンスと指定した Guid オブジェクトが同じ値を表しているかどうかを示す値を返します。

Equals(Object)

このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。

GetHashCode()

このインスタンスのハッシュ コードを返します。

NewGuid()

Guid 構造体の新しいインスタンスを初期化します。

Parse(ReadOnlySpan<Char>)

GUID を表す読み取り専用の文字スパンを、それと等価な Guid 構造体に変換します。

Parse(ReadOnlySpan<Char>, IFormatProvider)

文字のスパンを値に解析します。

Parse(String)

GUID の文字列形式を、等価の Guid 構造体に変換します。

Parse(String, IFormatProvider)

文字列を値に解析します。

ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>)

文字列が指定の形式であれば、GUID の文字スパン形式を等価の Guid 構造体に変換します。

ParseExact(String, String)

文字列が指定の形式であれば、GUID の文字列形式を等価の Guid 構造体に変換します。

ToByteArray()

このインスタンスの値を格納する 16 要素のバイト配列を返します。

ToString()

このインスタンスの値の文字列形式をレジストリ形式で返します。

ToString(String)

指定した書式指定子に従って、この Guid インスタンスの値を文字列形式で返します。

ToString(String, IFormatProvider)

指定した書式指定子とカルチャ固有の書式情報に従って、Guid クラスのこのインスタンスの値を文字列形式で返します。

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>)

指定された文字スパンに現在の GUID インスタンスの書式を設定しようとします。

TryParse(ReadOnlySpan<Char>, Guid)

GUID の表現を含む文字の指定した読み取り専用のスパンを、等価の Guid 構造体に変換します。

TryParse(ReadOnlySpan<Char>, IFormatProvider, Guid)

文字のスパンを値に解析しようとします。

TryParse(String, Guid)

GUID の文字列形式を、等価の Guid 構造体に変換します。

TryParse(String, IFormatProvider, Guid)

文字列を値に解析しようとします。

TryParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, Guid)

文字列が指定の形式であれば、GUID を表す文字のスパンを等価の Guid 構造体に変換します。

TryParseExact(String, String, Guid)

文字列が指定の形式であれば、GUID の文字列形式を等価の Guid 構造体に変換します。

TryWriteBytes(Span<Byte>)

現在の GUID インスタンスをバイトのスパンに書き込もうとします。

演算子

Equality(Guid, Guid)

2 つの指定された Guid オブジェクトの値が等しいかどうかを示します。

GreaterThan(Guid, Guid)

2 つの値を比較して、どちらが大きいかを判断します。

GreaterThanOrEqual(Guid, Guid)

2 つの値を比較して、どちらが大きいか等しいかを判断します。

Inequality(Guid, Guid)

2 つの指定された Guid オブジェクトの値が等しくないかどうかを示します。

LessThan(Guid, Guid)

2 つの値を比較して、どちらが小さいかを判断します。

LessThanOrEqual(Guid, Guid)

2 つの値を比較して、次の値以下を決定します。

明示的なインターフェイスの実装

IComparable.CompareTo(Object)

指定した Guid オブジェクトとこのインスタンスを比較し、これらの相対値を示す値を返します。

IFormattable.ToString(String, IFormatProvider)

指定した書式指定子とカルチャ固有の書式情報に従って、このインスタンスの値を文字列形式で返します。

ISpanFormattable.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

現在のインスタンスの値を、指定された文字数のスパンに書式設定しようとします。

適用対象