Exchange(T) Method (T, T)

Interlocked.Exchange(Of T) Method (T%, T)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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)

'Declaration
Public Shared Function Exchange(Of T As Class) ( _
	ByRef location1 As T, _
	value As T _
) As T

Type Parameters

T

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

Parameters

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

Return Value

Type: T
The original value of location1.

ExceptionCondition
NullReferenceException

The address of location1 is a null pointer.

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

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft