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.
Exceptions
- ArgumentNullException
b
is null.- ArgumentException
b
is not 16 bytes long.
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
intThe first 4 bytes of the GUID.
b
shortThe next 2 bytes of the GUID.
c
shortThe next 2 bytes of the GUID.
d
byteThe next byte of the GUID.
e
byteThe next byte of the GUID.
f
byteThe next byte of the GUID.
g
byteThe next byte of the GUID.
h
byteThe next byte of the GUID.
i
byteThe next byte of the GUID.
j
byteThe next byte of the GUID.
k
byteThe 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)
Initializes a new instance of the Guid structure by using the value represented by the specified string.
public Guid(string g)
Parameters
g
stringA string that contains a GUID in one of the following formats ("d" represents a hexadecimal digit whose case is ignored):
32 contiguous hexadecimal digits:
dddddddddddddddddddddddddddddddd
-or-
Groups of 8, 4, 4, 4, and 12 hexadecimal digits with hyphens between the groups. The entire GUID can optionally be enclosed in matching braces or parentheses:
dddddddd-dddd-dddd-dddd-dddddddddddd
-or-
{dddddddd-dddd-dddd-dddd-dddddddddddd}
-or-
(dddddddd-dddd-dddd-dddd-dddddddddddd)
-or-
Groups of 8, 4, and 4 hexadecimal digits, and a subset of eight groups of 2 hexadecimal digits, with each group prefixed by "0x" or "0X", and separated by commas. The entire GUID, as well as the subset, is enclosed in matching braces:
{0xdddddddd, 0xdddd, 0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}}
All braces, commas, and "0x" prefixes are required. All embedded spaces are ignored. All leading zeros in a group are ignored.
The hexadecimal digits shown in a group are the maximum number of meaningful hexadecimal digits that can appear in that group. You can specify from 1 to the number of hexadecimal digits shown for a group. The specified digits are assumed to be the low-order digits of the group.
Exceptions
- ArgumentNullException
g
is null.- ArgumentException
g
is not in a recognized format.
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
uintThe first 4 bytes of the GUID.
b
ushortThe next 2 bytes of the GUID.
c
ushortThe next 2 bytes of the GUID.
d
byteThe next byte of the GUID.
e
byteThe next byte of the GUID.
f
byteThe next byte of the GUID.
g
byteThe next byte of the GUID.
h
byteThe next byte of the GUID.
i
byteThe next byte of the GUID.
j
byteThe next byte of the GUID.
k
byteThe 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
Methods
CompareTo(object)
Compares this instance to a specified object and returns an indication of their relative values.
public int CompareTo(object value)
Parameters
Returns
- int
A signed number indicating the relative values of this instance and value. (0 = This instance is equal to
value
., -1 = This instance is less thanvalue
., +1 = This instance is greater thanvalue
, orvalue
is null.)
Exceptions
- ArgumentException
value
is not a Guid.
Equals(object)
Returns a value that indicates whether this instance is equal to a specified object.
public override bool Equals(object o)
Parameters
o
objectThe object to compare with this instance.
Returns
Remarks
Two Guid objects are equal if they have identical byte values.
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 in registry format.
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
stringA string containing the GUID to convert.
result
GuidWhen this method returns, contains the parsed value. If the method returns true, result contains a valid Guid. If the method returns false, result equals Empty.