Freigeben über


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

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

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)

Syntax

'Declaration
<ComVisibleAttribute(False)> _
<SecuritySafeCriticalAttribute> _
Public Shared Function Exchange(Of T As Class) ( _
    ByRef location1 As T, _
    value As T _
) As T
[ComVisibleAttribute(false)]
[SecuritySafeCriticalAttribute]
public static T Exchange<T>(
    ref T location1,
    T value
)
where T : class

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.

Exceptions

Exception Condition
NullReferenceException

The address of location1 is a null pointer.

Remarks

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.

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.