Breyta

Deila með


Interlocked.Add Method

Definition

Adds two integers and replaces the first integer with the sum, as an atomic operation.

Overloads

Add(Int32, Int32)

Adds two 32-bit integers and replaces the first integer with the sum, as an atomic operation.

Add(Int64, Int64)

Adds two 64-bit integers and replaces the first integer with the sum, as an atomic operation.

Add(UInt32, UInt32)

Adds two 32-bit unsigned integers and replaces the first integer with the sum, as an atomic operation.

Add(UInt64, UInt64)

Adds two 64-bit unsigned integers and replaces the first integer with the sum, as an atomic operation.

Add(Int32, Int32)

Source:
Interlocked.CoreCLR.cs
Source:
Interlocked.CoreCLR.cs
Source:
Interlocked.CoreCLR.cs

Adds two 32-bit integers and replaces the first integer with the sum, as an atomic operation.

public:
 static int Add(int % location1, int value);
public static int Add (ref int location1, int value);
static member Add : int * int -> int
Public Shared Function Add (ByRef location1 As Integer, value As Integer) As Integer

Parameters

location1
Int32

A variable containing the first value to be added. The sum of the two values is stored in location1.

value
Int32

The value to be added to the integer at location1.

Returns

The new value that was stored at location1 by this operation.

Exceptions

The address of location1 is a null pointer.

Remarks

This method handles an overflow condition by wrapping: if the value at location1 is Int32.MaxValue and value is 1, the result is Int32.MinValue; if value is 2, the result is (Int32.MinValue + 1); and so on. No exception is thrown.

See also

Applies to

Add(Int64, Int64)

Source:
Interlocked.CoreCLR.cs
Source:
Interlocked.CoreCLR.cs
Source:
Interlocked.CoreCLR.cs

Adds two 64-bit integers and replaces the first integer with the sum, as an atomic operation.

public:
 static long Add(long % location1, long value);
public static long Add (ref long location1, long value);
static member Add : int64 * int64 -> int64
Public Shared Function Add (ByRef location1 As Long, value As Long) As Long

Parameters

location1
Int64

A variable containing the first value to be added. The sum of the two values is stored in location1.

value
Int64

The value to be added to the integer at location1.

Returns

The new value that was stored at location1 by this operation.

Exceptions

The address of location1 is a null pointer.

Remarks

This method handles an overflow condition by wrapping: if the value at location1 is Int64.MaxValue and value is 1, the result is Int64.MinValue; if value is 2, the result is (Int64.MinValue + 1); and so on. No exception is thrown.

See also

Applies to

Add(UInt32, UInt32)

Source:
Interlocked.cs
Source:
Interlocked.cs
Source:
Interlocked.cs

Important

This API is not CLS-compliant.

Adds two 32-bit unsigned integers and replaces the first integer with the sum, as an atomic operation.

public:
 static System::UInt32 Add(System::UInt32 % location1, System::UInt32 value);
[System.CLSCompliant(false)]
public static uint Add (ref uint location1, uint value);
[<System.CLSCompliant(false)>]
static member Add : uint32 * uint32 -> uint32
Public Shared Function Add (ByRef location1 As UInteger, value As UInteger) As UInteger

Parameters

location1
UInt32

A variable containing the first value to be added. The sum of the two values is stored in location1.

value
UInt32

The value to be added to the integer at location1.

Returns

The new value that was stored at location1 by this operation.

Attributes

Exceptions

The address of location1 is a null pointer.

Applies to

Add(UInt64, UInt64)

Source:
Interlocked.cs
Source:
Interlocked.cs
Source:
Interlocked.cs

Important

This API is not CLS-compliant.

Adds two 64-bit unsigned integers and replaces the first integer with the sum, as an atomic operation.

public:
 static System::UInt64 Add(System::UInt64 % location1, System::UInt64 value);
[System.CLSCompliant(false)]
public static ulong Add (ref ulong location1, ulong value);
[<System.CLSCompliant(false)>]
static member Add : uint64 * uint64 -> uint64
Public Shared Function Add (ByRef location1 As ULong, value As ULong) As ULong

Parameters

location1
UInt64

A variable containing the first value to be added. The sum of the two values is stored in location1.

value
UInt64

The value to be added to the integer at location1.

Returns

The new value that was stored at location1 by this operation.

Attributes

Exceptions

The address of location1 is a null pointer.

Applies to