Table of Contents

Struct Guid

Namespace
System
Assembly
mscorlib.dll

Represents a globally unique identifier (GUID).

public struct Guid
Inherited Members

Constructors

Guid(byte[])

Initializes a new instance of the Guid structure by using the specified array of bytes.

public Guid(byte[] b)

Parameters

b byte[]

A 16-element byte array containing values with which to initialize the GUID.

Guid(int, short, short, byte, byte, byte, byte, byte, byte, byte, byte)

Initializes a new instance of the Guid structure by using the specified integers and bytes.

public Guid(int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k)

Parameters

a int

The first 4 bytes of the GUID.

b short

The next 2 bytes of the GUID.

c short

The next 2 bytes of the GUID.

d byte

The next byte of the GUID.

e byte

The next byte of the GUID.

f byte

The next byte of the GUID.

g byte

The next byte of the GUID.

h byte

The next byte of the GUID.

i byte

The next byte of the GUID.

j byte

The next byte of the GUID.

k byte

The next byte of the GUID.

Remarks

Specifying individual bytes in this manner can be used to circumvent byte order restrictions (big-endian or little-endian byte order) on particular types of computers.

Guid(string)

Creates a new Guid based on the value in the string. The value is made up of hex digits speared by the dash ("-"). The string may begin and end with brackets ("{", "}").

The string must be of the form dddddddd-dddd-dddd-dddd-dddddddddddd. where d is a hex digit. (That is 8 hex digits, followed by 4, then 4, then 4, then 12) such as: "CA761232-ED42-11CE-BACD-00AA0057B223"

public Guid(string g)

Parameters

g string

String representation of new Guid.

Exceptions

ArgumentException

Guid(uint, ushort, ushort, byte, byte, byte, byte, byte, byte, byte, byte)

Initializes a new instance of the Guid structure by using the specified integers and bytes.

[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)

Parameters

a uint

The first 4 bytes of the GUID.

b ushort

The next 2 bytes of the GUID.

c ushort

The next 2 bytes of the GUID.

d byte

The next byte of the GUID.

e byte

The next byte of the GUID.

f byte

The next byte of the GUID.

g byte

The next byte of the GUID.

h byte

The next byte of the GUID.

i byte

The next byte of the GUID.

j byte

The next byte of the GUID.

k byte

The next byte of the GUID.

Remarks

Specifying the bytes in this manner avoids endianness issues.

Fields

Empty

A read-only instance of the Guid class which consists of all zeros.

public static readonly Guid Empty

Field Value

Guid

Methods

CompareTo(object)

Compares this instance to a specified object and returns an indication of their relative values.

public int CompareTo(object value)

Parameters

value object

Guid instance to compare, or null.

Returns

int

Indication of the relative values (0 = equal, -1 = this instance less, +1 = this instance greater)

Equals(object)

Returns a value that indicates whether this instance is equal to a specified object.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with this instance.

Returns

bool

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

The hash code for this instance.

NewGuid()

Initializes a new instance of the Guid structure.

public static Guid NewGuid()

Returns

Guid

A new GUID object.

ToByteArray()

Returns a 16-element byte array that contains the value of this instance.

public byte[] ToByteArray()

Returns

byte[]

A 16-element byte array.

ToString()

Returns a string representation of the value of this instance of the Guid structure.

public override string ToString()

Returns

string

The value of this Guid, formatted by using the "D" format specifier as follows:

         xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 

         where the value of the GUID is represented as a series of lowercase hexadecimal digits in groups of 8, 4, 4, 4, and 12 digits and separated by hyphens. An example of a return value is "382c74c3-721d-4f34-80e5-57657b6cbc27". To convert the hexadecimal digits from a through f to uppercase, call the <xref href="System.String.ToUpper" data-throw-if-not-resolved="false"></xref> method on the returned string.

TryParseGuidWithDashes(string, out Guid)

Creates a new Guid based on the value in the string. The value is made up of hex digits speared by the dash ("-"). The string may begin and end with brackets ("{", "}").

The string must be of the form dddddddd-dddd-dddd-dddd-dddddddddddd. where d is a hex digit. (That is 8 hex digits, followed by 4, then 4, then 4, then 12) such as: "CA761232-ED42-11CE-BACD-00AA0057B223"

public static bool TryParseGuidWithDashes(string guidString, out Guid result)

Parameters

guidString string

Guid string to parse.

result Guid

Resulting Guid.

Returns

bool