Struct Guid
Represents a globally unique identifier (GUID).
Inherited Members
Namespace: System
Assembly: mscorlib.dll
Syntax
public struct Guid
Constructors
| Improve this Doc View SourceGuid(Byte[])
Initializes a new instance of the Guid structure by using the specified array of bytes.
Declaration
public Guid(byte[] b)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | b | A 16-element byte array containing values with which to initialize the GUID. |
Guid(Int32, Int16, Int16, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte)
Initializes a new instance of the Guid structure by using the specified integers and bytes.
Declaration
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
Type | Name | Description |
---|---|---|
Int32 | a | The first 4 bytes of the GUID. |
Int16 | b | The next 2 bytes of the GUID. |
Int16 | c | The next 2 bytes of the GUID. |
Byte | d | The next byte of the GUID. |
Byte | e | The next byte of the GUID. |
Byte | f | The next byte of the GUID. |
Byte | g | The next byte of the GUID. |
Byte | h | The next byte of the GUID. |
Byte | i | The next byte of the GUID. |
Byte | j | The next byte of the GUID. |
Byte | k | 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"
Declaration
public Guid(string g)
Parameters
Type | Name | Description |
---|---|---|
String | g | String representation of new Guid. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
Guid(UInt32, UInt16, UInt16, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte)
Initializes a new instance of the Guid structure by using the specified integers and bytes.
Declaration
[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
Type | Name | Description |
---|---|---|
UInt32 | a | The first 4 bytes of the GUID. |
UInt16 | b | The next 2 bytes of the GUID. |
UInt16 | c | The next 2 bytes of the GUID. |
Byte | d | The next byte of the GUID. |
Byte | e | The next byte of the GUID. |
Byte | f | The next byte of the GUID. |
Byte | g | The next byte of the GUID. |
Byte | h | The next byte of the GUID. |
Byte | i | The next byte of the GUID. |
Byte | j | The next byte of the GUID. |
Byte | k | The next byte of the GUID. |
Remarks
Specifying the bytes in this manner avoids endianness issues.
Fields
| Improve this Doc View SourceEmpty
A read-only instance of the Guid class which consists of all zeros.
Declaration
public static readonly Guid Empty
Field Value
Type | Description |
---|---|
Guid |
Methods
| Improve this Doc View SourceCompareTo(Object)
Compares this instance to a specified object and returns an indication of their relative values.
Declaration
public int CompareTo(object value)
Parameters
Type | Name | Description |
---|---|---|
Object | value | Guid instance to compare, or null. |
Returns
Type | Description |
---|---|
Int32 | 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.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The object to compare with this instance. |
Returns
Type | Description |
---|---|
Boolean |
Overrides
| Improve this Doc View SourceGetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | The hash code for this instance. |
Overrides
| Improve this Doc View SourceNewGuid()
Initializes a new instance of the Guid structure.
Declaration
public static Guid NewGuid()
Returns
Type | Description |
---|---|
Guid | A new GUID object. |
ToByteArray()
Returns a 16-element byte array that contains the value of this instance.
Declaration
public byte[] ToByteArray()
Returns
Type | Description |
---|---|
Byte[] | A 16-element byte array. |
ToString()
Returns a string representation of the value of this instance of the Guid structure.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
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 ToUpper() method on the returned string. |
Overrides
| Improve this Doc View SourceTryParseGuidWithDashes(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"
Declaration
public static bool TryParseGuidWithDashes(string guidString, out Guid result)
Parameters
Type | Name | Description |
---|---|---|
String | guidString | Guid string to parse. |
Guid | result | Resulting Guid. |
Returns
Type | Description |
---|---|
Boolean |