Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Interlocked Class

  Switch on low bandwidth view
Members FilterMembers Filter
Frameworks FilterFrameworks Filter
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Interlocked..::.CompareExchange Method

Compares two values for equality and, if they are equal, replaces one of the values.

  NameDescription
Public methodStatic memberCompareExchange(Double%, Double, Double)Compares two double-precision floating point numbers for equality and, if they are equal, replaces one of the values.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCompareExchange(Int32%, Int32, Int32)Compares two 32-bit signed integers for equality and, if they are equal, replaces one of the values.
Public methodStatic memberCompareExchange(Int64%, Int64, Int64)Compares two 64-bit signed integers for equality and, if they are equal, replaces one of the values.
Public methodStatic memberCompareExchange(IntPtr%, IntPtr, IntPtr)Compares two platform-specific handles or pointers for equality and, if they are equal, replaces one of them.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCompareExchange(Object%, Object, Object)Compares two objects for reference equality and, if they are equal, replaces one of the objects.
Public methodStatic memberCompareExchange(Single%, Single, Single)Compares two single-precision floating point numbers for equality and, if they are equal, replaces one of the values.
Public methodStatic memberSupported by the .NET Compact FrameworkSupported by the XNA FrameworkCompareExchange<(Of <(T>)>)(T%, T, T)Compares two instances of the specified reference type T for equality and, if they are equal, replaces one of them.
Top
Community Content   What is Community Content?
Add new content RSS  Annotations
Doesn't state which      TimwiTerby ... Thomas Lee   |   Edit   |   Show History
"Compares two 32-bit signed integers for equality and, if they are equal, replaces one of the values."

Well, which one?
How these calls work      Thomas Lee   |   Edit   |   Show History

To answer TimwiTerby's question: The methods take three values (a, b and c) all of the same time - so there are several overloads. The call compares the value of parameter a with paramater c. If they are equal, then the value of a is replaced by the value of b. The method also returns the original value of a, if a and c are unequal or the new value of a if a and c are equal.

I've posted some samples on the invidudual method pages to illustrate how these methods work.

I think the writing on this page could be made clearer.

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker