Struct InterlockedInt32
A lightweight representation of an Interlocked (atomic) int.
public struct InterlockedInt32 : IEquatable<InterlockedInt32>, IComparable<InterlockedInt32>, IComparable
- Implements
- Inherited Members
- Extension Methods
Constructors
InterlockedInt32(int)
Creates a new InterlockedInt32 instance.
public InterlockedInt32(int value)
Parameters
valueintInitial value.
Properties
Value
Current value.
public int Value { get; }
Property Value
Methods
Add(int)
Adds provided value to the current Value.
public int Add(int value)
Parameters
valueintValue to add.
Returns
And(int)
Performs a bitwise and operation on the current Value and the provided value
and stores the result in Value.
public int And(int value)
Parameters
valueintValue to bitwise and.
Returns
CompareExchange(int, int)
Sets Value to the provided value
only if the current Value is equal to the provided comparand
and returns the old value.
public int CompareExchange(int value, int comparand)
Parameters
Returns
CompareTo(InterlockedInt32)
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 the sort order as the other object.
[Pure]
public int CompareTo(InterlockedInt32 other)
Parameters
otherInterlockedInt32An object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
CompareTo(object?)
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 the sort order as the other object.
[Pure]
public int CompareTo(object? obj)
Parameters
objobjectAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes objin the sort order.Zero This instance occurs in the same position in the sort order as obj.Greater than zero This instance follows objin the sort order.
Exceptions
- ArgumentException
objis not the same type as this instance.
Decrement()
Decrements the current Value by 1.
public int Decrement()
Returns
Equals(InterlockedInt32)
Indicates whether the current object is equal to another object of the same type.
[Pure]
public bool Equals(InterlockedInt32 other)
Parameters
otherInterlockedInt32An object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
[Pure]
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
Exchange(int)
Sets Value to the provided value and returns the old value.
public int Exchange(int value)
Parameters
valueintValue to set.
Returns
GetHashCode()
Returns the hash code for this instance.
[Pure]
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Increment()
Increments the current Value by 1.
public int Increment()
Returns
Or(int)
Performs a bitwise or operation on the current Value and the provided value
and stores the result in Value.
public int Or(int value)
Parameters
valueintValue to bitwise or.
Returns
Subtract(int)
Subtracts provided value from the current Value.
public int Subtract(int value)
Parameters
valueintValue to subtract.
Returns
ToString()
Returns a string representation of this InterlockedInt32 instance.
[Pure]
public override string ToString()
Returns
- string
String representation.
Write(int)
Sets Value to the provided value.
public bool Write(int value)
Parameters
valueintValue to set.
Returns
- bool
true when value has changed, otherwise false.
Write(int, int)
public bool Write(int value, int expected)
Parameters
Returns
- bool
true when value has changed, otherwise false.
Operators
operator ==(InterlockedInt32, InterlockedInt32)
Checks if a is equal to b.
public static bool operator ==(InterlockedInt32 a, InterlockedInt32 b)
Parameters
aInterlockedInt32First operand.
bInterlockedInt32Second operand.
Returns
- bool
true when operands are equal, otherwise false.
operator >(InterlockedInt32, InterlockedInt32)
Checks if a is greater than b.
public static bool operator >(InterlockedInt32 a, InterlockedInt32 b)
Parameters
aInterlockedInt32First operand.
bInterlockedInt32Second operand.
Returns
- bool
true when
ais greater thanb, otherwise false.
operator >=(InterlockedInt32, InterlockedInt32)
Checks if a is greater than or equal to b.
public static bool operator >=(InterlockedInt32 a, InterlockedInt32 b)
Parameters
aInterlockedInt32First operand.
bInterlockedInt32Second operand.
Returns
- bool
true when
ais greater than or equal tob, otherwise false.
operator !=(InterlockedInt32, InterlockedInt32)
Checks if a is not equal to b.
public static bool operator !=(InterlockedInt32 a, InterlockedInt32 b)
Parameters
aInterlockedInt32First operand.
bInterlockedInt32Second operand.
Returns
- bool
true when operands are not equal, otherwise false.
operator <(InterlockedInt32, InterlockedInt32)
Checks if a is less than b.
public static bool operator <(InterlockedInt32 a, InterlockedInt32 b)
Parameters
aInterlockedInt32First operand.
bInterlockedInt32Second operand.
Returns
- bool
true when
ais less thanb, otherwise false.
operator <=(InterlockedInt32, InterlockedInt32)
Checks if a is less than or equal to b.
public static bool operator <=(InterlockedInt32 a, InterlockedInt32 b)
Parameters
aInterlockedInt32First operand.
bInterlockedInt32Second operand.
Returns
- bool
true when
ais less than or equal tob, otherwise false.