InterlockedReference<T> Struct
Implements thread-safe management of an object reference.
public struct InterlockedReference<T> : IEquatable<InterlockedReference<T>>, IEquatable<T?> where T : classType parameters
T- The type of the stored reference.
Constructors
| Name | Description |
|---|---|
| InterlockedReference(T?) | Initializes a new instance of the InterlockedReference<T> struct. |
InterlockedReference(T?)
Initializes a new instance of the InterlockedReference<T> struct.
public InterlockedReference(T? value)Parameters
valueT?- The initial value of the reference.
Properties
| Name | Description |
|---|---|
| IsNull | Gets a value indicating whether the reference stored in an InterlockedReference<T> is null. |
| Value | Gets or sets the reference stored in an InterlockedReference<T>. This property is thread-safe. |
IsNull
Gets a value indicating whether the reference stored in an InterlockedReference<T> is null.
public bool IsNull { get; }Property value
bool true if the reference is null; false otherwise.
Value
Gets or sets the reference stored in an InterlockedReference<T>.
This property is thread-safe.
public T? Value { get; set; }Property value
T?
Methods
| Name | Description |
|---|---|
| CompareExchange(T?, T?) | Compares the value of an interlocked reference to a given comparand and, if they are equal, replaces it with a given value. |
| Equals(InterlockedReference<T>) | Indicates whether the current object is equal to another object of the same type. |
| Equals(object?) | Indicates whether this instance and a specified object are equal. |
| Equals(T?) | Indicates whether the current object is equal to another object of the same type. |
| Exchange(T?) | Sets the value of an interlocked reference. |
| GetHashCode() | Returns the hash code for this instance. |
| ToString() | Returns the fully qualified type name of this instance. |
CompareExchange(T?, T?)
Compares the value of an interlocked reference to a given comparand and, if they are equal, replaces it with a given value.
public T? CompareExchange(T? value, T? comparand)Parameters
valueT?- The value that replaces the destination value if the comparison by reference results in equality.
comparandT?- The value that is compared by reference to the value of this instance.
Returns
T? The original value of this instance.
Equals overloads
Equals(InterlockedReference<T>)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(InterlockedReference<T> other)Parameters
otherInterlockedReference<T>- An object to compare with this object.
Returns
bool true if the current object is equal to the other parameter; otherwise, false.
Equals(object?)
Equals(T?)
Exchange(T?)
Sets the value of an interlocked reference.
public T? Exchange(T? value)Parameters
valueT?- The value to set.
Returns
T? The previous value of this instance.
GetHashCode()
ToString()
Operators
| Name | Description |
|---|---|
| operator ==(InterlockedReference<T>, InterlockedReference<T>) | Determines whether two specified interlocked references have the same value. |
| operator ==(InterlockedReference<T>, T?) | Determines whether the value of a specified interlocked reference is the same as a specified value. |
| operator !=(InterlockedReference<T>, InterlockedReference<T>) | Determines whether two specified interlocked references have different values. |
| operator !=(InterlockedReference<T>, T?) | Determines whether the value of a specified interlocked reference is different from a specified value. |
op_Equality overloads
operator ==(InterlockedReference<T>, InterlockedReference<T>)
Determines whether two specified interlocked references have the same value.
public static bool operator ==(InterlockedReference<T> a, InterlockedReference<T> b)Parameters
aInterlockedReference<T>- The first instance to compare.
bInterlockedReference<T>- The second instance to compare.
Returns
bool true if the value of a is the same as the value of b; otherwise, false.
operator ==(InterlockedReference<T>, T?)
Determines whether the value of a specified interlocked reference is the same as a specified value.
public static bool operator ==(InterlockedReference<T> a, T? b)Parameters
aInterlockedReference<T>- The interlocked reference to compare.
bT?- The reference to compare.
Returns
bool true if the value of a is the same as the value of b; otherwise, false.
op_Inequality overloads
operator !=(InterlockedReference<T>, InterlockedReference<T>)
Determines whether two specified interlocked references have different values.
public static bool operator !=(InterlockedReference<T> a, InterlockedReference<T> b)Parameters
aInterlockedReference<T>- The first instance to compare.
bInterlockedReference<T>- The second instance to compare.
Returns
bool true if the value of a is different from the value of b; otherwise, false.
operator !=(InterlockedReference<T>, T?)
Determines whether the value of a specified interlocked reference is different from a specified value.
public static bool operator !=(InterlockedReference<T> a, T? b)Parameters
aInterlockedReference<T>- The interlocked reference to compare.
bT?- The reference to compare.
Returns
bool true if the value of a is different from the value of b; otherwise, false.