Guid コンストラクター

定義

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

オーバーロード

Guid(Byte[])

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

Guid(ReadOnlySpan<Byte>)

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

Guid(String)

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

Guid(ReadOnlySpan<Byte>, Boolean)
Guid(Int32, Int16, Int16, Byte[])

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

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

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

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

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

Guid(Byte[])

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

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

public:
 Guid(cli::array <System::Byte> ^ b);
public Guid (byte[] b);
new Guid : byte[] -> Guid
Public Sub New (b As Byte())

パラメーター

b
Byte[]

GUID を初期化するための値を含む 16 要素のバイト配列。

例外

bnullです。

b の長さが 16 バイトではありません。

適用対象

Guid(ReadOnlySpan<Byte>)

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

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

public:
 Guid(ReadOnlySpan<System::Byte> b);
public Guid (ReadOnlySpan<byte> b);
new Guid : ReadOnlySpan<byte> -> Guid
Public Sub New (b As ReadOnlySpan(Of Byte))

パラメーター

b
ReadOnlySpan<Byte>

GUID を表すバイトを含む読み取り専用のスパン。 スパンの長さは、ちょうど 16 バイトである必要があります。

例外

スパンの長さは、ちょうど 16 バイトである必要があります。

適用対象

Guid(String)

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

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

public:
 Guid(System::String ^ g);
public Guid (string g);
new Guid : string -> Guid
Public Sub New (g As String)

パラメーター

g
String

次のいずれかの形式の GUID を保持する文字列 ("d" は、大文字と小文字が区別されない 16 進数の文字を表します)。

連続する 32 桁の 16 進数:

dddddddddddddddddddddddddddddddd

または

8、4、4、4、および 12 桁の 16 進数のグループで、グループ間にハイフンが付きます。 左右が対応している中かっこや丸かっこで GUID 全体を囲むこともできます。

dddddddd-dddd-dddd-dddd-dddddddddddd

または

{dddddddd-dddd-dddd-dddd-dddddddddddd}

または

(dddddddd-dddd-dddd-dddd-dddddddddddd)

または

8 桁、4 桁、4 桁の 16 進数のグループ、および 2 桁の 16 進数の 8 つのグループのサブセット。各グループの先頭には "0x" または "0X" が付き、コンマで区切られます。 GUID 全体およびサブセットは、左右が対応している中かっこで囲みます。

{0xdddddddd, 0xdddd, 0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}}

中かっこ、コンマ、プリフィックスの "0x" はすべて必須です。 埋め込まれている空白はすべて無視されます。 グループの先頭にある 0 はすべて無視されます。

グループに表示される 16 進数は、そのグループに表示できる意味のある 16 進数の最大数です。 1 からグループに表示される 16 進数の数を指定できます。 指定した数字は、そのグループの下位の桁と見なされます。

例外

gnullです。

g の形式が正しくありません。

g の形式が正しくありません。

次の例では、「解説」セクションに記載されている各文字列をコンストラクターに Guid(String) 渡します。

string[] guidStrings = { "ca761232ed4211cebacd00aa0057b223",
                         "CA761232-ED42-11CE-BACD-00AA0057B223",
                         "{CA761232-ED42-11CE-BACD-00AA0057B223}",
                         "(CA761232-ED42-11CE-BACD-00AA0057B223)",
                         "{0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}" };
foreach (var guidString in guidStrings)
{
    var guid = new Guid(guidString);
    Console.WriteLine($"Original string: {guidString}");
    Console.WriteLine($"Guid:            {guid}");
    Console.WriteLine();
}

// The example displays the following output:
//    Original string: ca761232ed4211cebacd00aa0057b223
//    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
//
//    Original string: CA761232-ED42-11CE-BACD-00AA0057B223
//    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
//
//    Original string: {CA761232-ED42-11CE-BACD-00AA0057B223}
//    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
//
//    Original string: (CA761232-ED42-11CE-BACD-00AA0057B223)
//    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
//
//    Original string: {0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}
//    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
open System

let guidStrings =
    [ "ca761232ed4211cebacd00aa0057b223"
      "CA761232-ED42-11CE-BACD-00AA0057B223"
      "{CA761232-ED42-11CE-BACD-00AA0057B223}"
      "(CA761232-ED42-11CE-BACD-00AA0057B223)"
      "{0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}" ]

for guidString in guidStrings do
    let guid = Guid guidString
    printfn $"Original string: {guidString}"
    printfn $"Guid:            {guid}\n"

// The example displays the following output:
//    Original string: ca761232ed4211cebacd00aa0057b223
//    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
//
//    Original string: CA761232-ED42-11CE-BACD-00AA0057B223
//    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
//
//    Original string: {CA761232-ED42-11CE-BACD-00AA0057B223}
//    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
//
//    Original string: (CA761232-ED42-11CE-BACD-00AA0057B223)
//    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
//
//    Original string: {0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}
//    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
Module Example
   Public Sub Main()
      Dim guidStrings() As String = { "ca761232ed4211cebacd00aa0057b223",
                                      "CA761232-ED42-11CE-BACD-00AA0057B223", 
                                      "{CA761232-ED42-11CE-BACD-00AA0057B223}", 
                                      "(CA761232-ED42-11CE-BACD-00AA0057B223)", 
                                      "{0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}" }
      For Each guidString In guidStrings
         Dim guid As New Guid(guidString)
         Console.WriteLine("Original string: {0}", guidString)
         Console.WriteLine("Guid:            {0}", guid)
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'    Original string: ca761232ed4211cebacd00aa0057b223
'    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
'    
'    Original string: CA761232-ED42-11CE-BACD-00AA0057B223
'    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
'    
'    Original string: {CA761232-ED42-11CE-BACD-00AA0057B223}
'    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
'    
'    Original string: (CA761232-ED42-11CE-BACD-00AA0057B223)
'    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223
'    
'    Original string: {0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}
'    Guid:            ca761232-ed42-11ce-bacd-00aa0057b223

注釈

パラメーターのアルファベットの 16 進数は g 、大文字または小文字にすることができます。 たとえば、次の文字列は同じ GUID を表します。

"ca761232ed4211cebacd00aa0057b223"

"CA761232-ED42-11CE-BACD-00AA0057B223"

"{CA761232-ED42-11CE-BACD-00AA0057B223}"

"(CA761232-ED42-11CE-BACD-00AA0057B223)"

"{0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}} "

適用対象

Guid(ReadOnlySpan<Byte>, Boolean)

Source:
Guid.cs
Source:
Guid.cs
public:
 Guid(ReadOnlySpan<System::Byte> b, bool bigEndian);
public Guid (ReadOnlySpan<byte> b, bool bigEndian);
new Guid : ReadOnlySpan<byte> * bool -> Guid
Public Sub New (b As ReadOnlySpan(Of Byte), bigEndian As Boolean)

パラメーター

bigEndian
Boolean

適用対象

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

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

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

public:
 Guid(int a, short b, short c, cli::array <System::Byte> ^ d);
public Guid (int a, short b, short c, byte[] d);
new Guid : int * int16 * int16 * byte[] -> Guid
Public Sub New (a As Integer, b As Short, c As Short, d As Byte())

パラメーター

a
Int32

GUID の最初の 4 バイト。

b
Int16

GUID の次の 2 バイト。

c
Int16

GUID の次の 2 バイト。

d
Byte[]

GUID の残りの 8 バイト。

例外

dnullです。

d の長さが 8 バイトではありません。

Guid(1,2,3,new byte[]{0,1,2,3,4,5,6,7})Guidは、"00000001-0002-0003-0001-020304050607" に対応する を作成します。

適用対象

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

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

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

public:
 Guid(int a, short b, short c, System::Byte d, System::Byte e, System::Byte f, System::Byte g, System::Byte h, System::Byte i, System::Byte j, System::Byte k);
public Guid (int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k);
new Guid : int * int16 * int16 * byte * byte * byte * byte * byte * byte * byte * byte -> Guid
Public Sub New (a As Integer, b As Short, c As Short, d As Byte, e As Byte, f As Byte, g As Byte, h As Byte, i As Byte, j As Byte, k As Byte)

パラメーター

a
Int32

GUID の最初の 4 バイト。

b
Int16

GUID の次の 2 バイト。

c
Int16

GUID の次の 2 バイト。

d
Byte

GUID の次のバイト。

e
Byte

GUID の次のバイト。

f
Byte

GUID の次のバイト。

g
Byte

GUID の次のバイト。

h
Byte

GUID の次のバイト。

i
Byte

GUID の次のバイト。

j
Byte

GUID の次のバイト。

k
Byte

GUID の次のバイト。

次の例では、文字列表現が "0000000a-000b-000c-0001-020304050607" である GUID を作成します。

var g = new Guid(0xA, 0xB, 0xC,
                  new Byte[] { 0, 1, 2, 3, 4, 5, 6, 7 } );
Console.WriteLine($"{g:B}");

// The example displays the following output:
//        {0000000a-000b-000c-0001-020304050607}
open System

let g = Guid(0xA, 0xBs, 0xCs, [| 0uy..7uy |])
printfn $"{g:B}"

// The example displays the following output:
//        {0000000a-000b-000c-0001-020304050607}
Module Example
   Public Sub Main()
      Dim g As New Guid(&hA, &hB, &hC, 
                        New Byte() { 0, 1, 2, 3, 4, 5, 6, 7 } )
      Console.WriteLine("{0:B}", g)
   End Sub
End Module
' The example displays the following output:
'   {0000000a-000b-000c-0001-020304050607}

注釈

この方法で個々のバイトを指定すると、特定の種類のコンピューターでバイト順の制限 (ビッグ エンディアンまたはリトル エンディアンのバイト順) を回避するために使用できます。

適用対象

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

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

重要

この API は CLS 準拠ではありません。

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

public:
 Guid(System::UInt32 a, System::UInt16 b, System::UInt16 c, System::Byte d, System::Byte e, System::Byte f, System::Byte g, System::Byte h, System::Byte i, System::Byte j, System::Byte k);
[System.CLSCompliant(false)]
public Guid (uint a, ushort b, ushort c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k);
[<System.CLSCompliant(false)>]
new Guid : uint32 * uint16 * uint16 * byte * byte * byte * byte * byte * byte * byte * byte -> Guid
Public Sub New (a As UInteger, b As UShort, c As UShort, d As Byte, e As Byte, f As Byte, g As Byte, h As Byte, i As Byte, j As Byte, k As Byte)

パラメーター

a
UInt32

GUID の最初の 4 バイト。

b
UInt16

GUID の次の 2 バイト。

c
UInt16

GUID の次の 2 バイト。

d
Byte

GUID の次のバイト。

e
Byte

GUID の次のバイト。

f
Byte

GUID の次のバイト。

g
Byte

GUID の次のバイト。

h
Byte

GUID の次のバイト。

i
Byte

GUID の次のバイト。

j
Byte

GUID の次のバイト。

k
Byte

GUID の次のバイト。

属性

注釈

この方法でバイトを指定すると、エンディアンの問題を回避できます。

適用対象