Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Compares two 32-bit signed integers for equality and, if they are equal, replaces one of the values.
Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Shared Function CompareExchange ( _
ByRef location1 As Integer, _
value As Integer, _
comparand As Integer _
) As Integer
public static int CompareExchange(
ref int location1,
int value,
int comparand
)
public:
static int CompareExchange(
int% location1,
int value,
int comparand
)
static member CompareExchange :
location1:int byref *
value:int *
comparand:int -> int
public static function CompareExchange(
location1 : int,
value : int,
comparand : int
) : int
Parameters
- location1
Type: System. . :: . .Int32%
The destination, whose value is compared with comparand and possibly replaced.
- value
Type: System. . :: . .Int32
The value that replaces the destination value if the comparison results in equality.
- comparand
Type: System. . :: . .Int32
The value that is compared to the value at location1.
Return Value
Type: System. . :: . .Int32
The original value in location1.
Remarks
If comparand and the value in location1 are equal, then value is stored in location1. Otherwise, no operation is performed. The compare and exchange operations are performed as an atomic operation. The return value of CompareExchange is the original value in location1, whether or not the exchange takes place.
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see dd66cd4c-b087-415f-9c3e-94e3a1835f74.