Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
struct System.​Guid
Assembly: System.Runtime
Implemented Interfaces
- IComparable
- IComparable`1
- IEquatable`1
- ISpanFormattable (Inherits: IFormattable)
- ISpanParsable`1 (Inherits: IParsable<​Guid>)
- IUtf8SpanFormattable
- IUtf8SpanParsable`1
Represents a globally unique identifier (GUID).
Fields and Constants
public static readonly
Guid
Empty
A read-only instance of the <see cref="T:System.Guid" /> structure whose value is all zeros.
Properties
public static
Guid
AllBitsSet
Gets a <see cref="T:System.Guid" /> where all bits are set.
public
int
Variant
Gets the value of the variant field for the <see cref="T:System.Guid" /> .
public
int
Version
Gets the value of the version field for the <see cref="T:System.Guid" /> .
Methods
public
int
CompareTo​(Guid value)
Compares this instance to a specified <see cref="T:System.Guid" /> object and returns an indication of their relative values.
Returns A signed number indicating the relative values of this instance and <paramref name="value" /> .
<list type="table">
<listheader>
<term> Return value</term>
<description> Description</description>
</listheader>
<item>
<term> A negative integer</term>
<description> This instance is less than <paramref name="value" />.</description>
</item>
<item>
<term> Zero</term>
<description> This instance is equal to <paramref name="value" />.</description>
</item>
<item>
<term> A positive integer</term>
<description> This instance is greater than <paramref name="value" />.</description>
</item>
</list>
value
An object to compare to this instance.
public
int
CompareTo​(object value)
Compares this instance to a specified object and returns an indication of their relative values.
Returns A signed number indicating the relative values of this instance and <paramref name="value" /> .
<list type="table">
<listheader>
<term> Return value</term>
<description> Description</description>
</listheader>
<item>
<term> A negative integer</term>
<description> This instance is less than <paramref name="value" />.</description>
</item>
<item>
<term> Zero</term>
<description> This instance is equal to <paramref name="value" />.</description>
</item>
<item>
<term> A positive integer</term>
<description> This instance is greater than <paramref name="value" />, or <paramref name="value" /> is <see langword="null" />.</description>
</item>
</list>
value
An object to compare, or <see langword="null" /> .
public static
Guid
CreateVersion7​()
Creates a new <see cref="T:System.Guid" /> according to RFC 9562, following the Version 7 format.
Returns A new <see cref="T:System.Guid" /> according to RFC 9562, following the Version 7 format.
public static
Guid
CreateVersion7​(DateTimeOffset timestamp)
Creates a new <see cref="T:System.Guid" /> according to RFC 9562, following the Version 7 format.
Returns A new <see cref="T:System.Guid" /> according to RFC 9562, following the Version 7 format.
timestamp
The date-time offset used to determine the Unix Epoch timestamp.
public
bool
Equals​(Guid g)
Returns a value indicating whether this instance and a specified <see cref="T:System.Guid" /> object represent the same value.
Returns <see langword="true" /> if <paramref name="g" /> is equal to this instance; otherwise, <see langword="false" /> .
g
An object to compare to this instance.
public
bool
Equals​(object o)
Returns a value that indicates whether this instance is equal to a specified object.
Returns <see langword="true" /> if <paramref name="o" /> is a <see cref="T:System.Guid" /> that has the same value as this instance; otherwise, <see langword="false" /> .
o
The object to compare with this instance.
public
int
GetHashCode​()
Returns the hash code for this instance.
Returns The hash code for this instance.
public static
Guid
NewGuid​()
Initializes a new instance of the <see cref="T:System.Guid" /> structure.
Returns A new GUID object.
public static
Guid
Parse​(ReadOnlySpan<​byte> utf8Text,
IFormatProvider? provider)
Parses a span of UTF-8 characters into a value.
Returns The result of parsing <code data-dev-comment-type="paramref">utf8Text</code> .
utf8Text
The span of UTF-8 characters to parse.
provider
An object that provides culture-specific formatting information about <code data-dev-comment-type="paramref">utf8Text</code> .
public static
Guid
Parse​(ReadOnlySpan<​char> input)
Converts a read-only character span that represents a GUID to the equivalent <see cref="T:System.Guid" /> structure.
Returns A structure that contains the value that was parsed.
input
A read-only span containing the bytes representing a GUID.
public static
Guid
Parse​(ReadOnlySpan<​char> s,
IFormatProvider? provider)
Parses a span of characters into a value.
Returns The result of parsing <paramref name="s" /> .
s
The span of characters to parse.
provider
An object that provides culture-specific formatting information about <paramref name="s" /> .
public static
Guid
Parse​(string input)
Converts the string representation of a GUID to the equivalent <see cref="T:System.Guid" /> structure.
Returns A structure that contains the value that was parsed.
input
The string to convert.
public static
Guid
Parse​(string s,
IFormatProvider? provider)
Parses a string into a value.
Returns The result of parsing <paramref name="s" /> .
s
The string to parse.
provider
An object that provides culture-specific formatting information about <paramref name="s" /> .
public static
Guid
ParseExact​(ReadOnlySpan<​char> input,
ReadOnlySpan<​char> format)
Converts the character span representation of a GUID to the equivalent <see cref="T:System.Guid" /> structure, provided that the string is in the specified format.
Returns A structure that contains the value that was parsed.
input
A read-only span containing the characters representing the GUID to convert.
format
A read-only span of characters representing one of the following specifiers that indicates the exact format to use when interpreting <paramref name="input" /> : "N", "D", "B", "P", or "X".
public static
Guid
ParseExact​(string input,
string format)
Converts the string representation of a GUID to the equivalent <see cref="T:System.Guid" /> structure, provided that the string is in the specified format.
Returns A structure that contains the value that was parsed.
input
The GUID to convert.
format
One of the following specifiers that indicates the exact format to use when interpreting <paramref name="input" /> : "N", "D", "B", "P", or "X".
public
byte[]
ToByteArray​()
Returns a 16-element byte array that contains the value of this instance.
Returns A 16-element byte array.
public
byte[]
ToByteArray​(bool bigEndian)
public
string
ToString​()
Returns a string representation of the value of this instance in registry format.
Returns The value of this <see cref="T:System.Guid" /> , formatted by using the "D" format specifier as follows:
<c>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</c>
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 <see cref="M:System.String.ToUpper" /> method on the returned string.
public
string
ToString​(string format)
Returns a string representation of the value of this <see cref="T:System.Guid" /> instance, according to the provided format specifier.
Returns The value of this <see cref="T:System.Guid" /> , represented as a series of lowercase hexadecimal digits in the specified format.
format
A single format specifier that indicates how to format the value of this <see cref="T:System.Guid" /> . The <paramref name="format" /> parameter can be "N", "D", "B", "P", or "X". If <paramref name="format" /> is <see langword="null" /> or an empty string (""), "D" is used.
public
string
ToString​(string format,
IFormatProvider provider)
Returns a string representation of the value of this instance of the <see cref="T:System.Guid" /> class, according to the provided format specifier and culture-specific format information.
Returns The value of this <see cref="T:System.Guid" /> , represented as a series of lowercase hexadecimal digits in the specified format.
format
A single format specifier that indicates how to format the value of this <see cref="T:System.Guid" /> . The <paramref name="format" /> parameter can be "N", "D", "B", "P", or "X". If <paramref name="format" /> is <see langword="null" /> or an empty string (""), "D" is used.
provider
(Reserved) An object that supplies culture-specific formatting information.
public
bool
TryFormat​(Span<​byte> utf8Destination,
Int32& bytesWritten,
ReadOnlySpan<​char> format = null)
public
bool
TryFormat​(Span<​char> destination,
Int32& charsWritten,
ReadOnlySpan<​char> format = null)
public static
bool
TryParse​(ReadOnlySpan<​byte> utf8Text,
Guid& result)
public static
bool
TryParse​(ReadOnlySpan<​byte> utf8Text,
IFormatProvider? provider,
Guid& result)
public static
bool
TryParse​(ReadOnlySpan<​char> s,
IFormatProvider? provider,
Guid& result)
public static
bool
TryParseExact​(ReadOnlySpan<​char> input,
ReadOnlySpan<​char> format,
Guid& result)
public
bool
TryWriteBytes​(Span<​byte> destination)
Tries to write the current GUID instance into a span of bytes.
Returns <see langword="true" /> if the GUID is successfully written to the specified span; <see langword="false" /> otherwise.
destination
When this method returns, the GUID as a span of bytes.
public
bool
TryWriteBytes​(Span<​byte> destination,
bool bigEndian,
Int32& bytesWritten)
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .