A GUID is a 128-bit integer used to identify information, nearly universally unique across space and time. GUIDs are often used to uniquely identify software components, interfaces, and objects.
The Guid struct in .NET provides methods for creating, manipulating, and comparing GUIDs.
Initializes a new instance of the Guid struct using the specified byte array.
b
: An array of 16 bytes to use for the GUID.Initializes a new instance of the Guid struct using the specified integer, three shorts, and five bytes.
a
: The most significant 4 bytes of the GUID.b
: The next 2 bytes of the GUID.c
: The next 2 bytes of the GUID.d
: The next byte of the GUID.e
: The next byte of the GUID.f
: The next byte of the GUID.g
: The next byte of the GUID.h
: The next byte of the GUID.i
: The next byte of the GUID.j
: The next byte of the GUID.k
: The least significant byte of the GUID.Initializes a new instance of the Guid struct using the specified string representation.
The string g
must be in one of the following formats:
"d
{d
d
d
d
d
d
d
d
d
d
d
"
"{
d
d
d
d
d
d
d
d
-
d
d
d
d
-
d
d
d
d
-
d
d
d
d
-
d
d
d
d
d
d
d
d
d
d
d
d
"
"{
d
:
d
d
d
d
d
d
d
d
:
d
d
d
d
d
d
d
d
:
d
d
d
d
d
d
d
d
d
d
d
d
"
"d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
"
"{
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
d
"
where d
is a hexadecimal digit.
g
: The string representation of the GUID.Gets the first four bytes of the GUID.
Gets the next two bytes of the GUID.
Gets the next two bytes of the GUID.
Gets the last eight bytes of the GUID.
Gets a new, empty GUID.
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in sort order as the other object.
value
: An object to compare with this instance.Compares the current instance with another Guid structure and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in sort order as the other object.
value
: A Guid structure to compare with the current instance.Returns a value indicating whether this instance is equal to a specified object.
obj
: An object to compare with this instance.true
if obj
is a Guid structure that has the same binary representation as this instance; otherwise, false
.Returns a value indicating whether this instance is equal to a specified Guid structure.
g
: A Guid structure to compare with this instance.true
if g
has the same binary representation as this instance; otherwise, false
.Returns the hash code for this instance.
Initializes a new instance of the Guid struct. The value is guaranteed to be unique among all possible values that can be generated.
using System;
public class Example
{
public static void Main()
{
Guid myGuid = Guid.NewGuid();
Console.WriteLine($"Generated GUID: {myGuid}");
}
}
Converts the value of this instance to its equivalent string representation.
Converts the value of this instance to its equivalent string representation using the specified format.
format
: A string that specifies the format of the GUID. The possible values are 'N', 'D', 'B', 'P', and 'X'.Tries to convert the string representation of a GUID to its Guid equivalent. A return value indicates whether the conversion succeeded.
s
: The string to parse.result
: When this method returns, contains the parsed GUID, if the conversion succeeded, or Guid.Empty if the conversion failed.true
if s
was converted successfully; otherwise, false
.Tries to convert the string representation of a GUID to its Guid equivalent using the specified format. A return value indicates whether the conversion succeeded.
s
: The string to parse.format
: The required format of s
.result
: When this method returns, contains the parsed GUID, if the conversion succeeded, or Guid.Empty if the conversion failed.true
if s
was converted successfully; otherwise, false
.Compares two Guid structures for equality.
Compares two Guid structures for inequality.
Compares two Guid structures to determine if the first is less than the second.
Compares two Guid structures to determine if the first is less than or equal to the second.
Compares two Guid structures to determine if the first is greater than the second.
Compares two Guid structures to determine if the first is greater than or equal to the second.