Share via


Interlocked.CompareExchange Method (Int64%, Int64, Int64)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Compares two 64-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
<SecuritySafeCriticalAttribute> _
Public Shared Function CompareExchange ( _
    ByRef location1 As Long, _
    value As Long, _
    comparand As Long _
) As Long
[SecuritySafeCriticalAttribute]
public static long CompareExchange(
    ref long location1,
    long value,
    long comparand
)

Parameters

  • location1
    Type: System.Int64%
    The destination whose value is compared with comparand and possibly replaced.
  • value
    Type: System.Int64
    The value that replaces the destination value if the comparison results in equality.
  • comparand
    Type: System.Int64
    The value that is compared to the value at location1.

Return Value

Type: System.Int64
The original value in location1.

Exceptions

Exception Condition
NullReferenceException

The address of location1 is a null pointer.

Remarks

If comparand and the value in location1 are equal, then value is stored in location1. Otherwise, no operation is performed. The comparison and the exchange are performed as an atomic operation. The return value of CompareExchange is the original value in location1, whether or not the exchange takes place.

Version Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 64-bit members of the Interlocked class are present but not supported.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.