Interlocked.CompareExchange Method (Object, Object, Object)
Compares two objects for reference equality and, if they are equal, replaces the first object.
Assembly: mscorlib (in mscorlib.dll)
public static object CompareExchange( ref object location1, object value, object comparand )
The destination object that is compared with comparand and possibly replaced.
The object that replaces the destination object if the comparison results in equality.
The object that is compared to the object at location1.
Return ValueType: System.Object
The original value in location1.
If comparand and the object 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.
Beginning with .NET Framework version 2.0, the CompareExchange<T>(T, T, T) method overload provides a type-safe alternative for reference types.
The objects are compared for reference equality, rather than Object.Equals. As a result, two boxed instances of the same value type (for example, the integer 3) always appear to be unequal, and no operation is performed. Do not use this overload with value types.
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 4.0
Windows Phone Silverlight
Available since 7.1
Available since 8.1