Interlocked.Exchange<T> Method (T%, T)

Sets a variable of the specified type T to a specified value and returns the original value, as an atomic operation.

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public static T Exchange<T>(
	ref T location1,
	T value
where T : class

Type Parameters


The type to be used for location1 and value. This type must be a reference type.


Type: T%
The variable to set to the specified value. This is a reference parameter (ref in C#, ByRef in Visual Basic).
Type: T
The value to which the location1 parameter is set.

Return Value

Type: T
The original value of location1.


The address of location1 is a null pointer.

This method supports only reference types. In Silverlight the Exchange method includes overloads for the value types Int32 and Int64, but does not support other value types.


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

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

Community Additions