#
Interlocked.Add
Interlocked.Add
Interlocked.Add
Interlocked.Add
Method

## Definition

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

## Overloads

Add(Int32, Int32) Add(Int32, Int32) Add(Int32, Int32) Add(Int32, Int32) |
Adds two 32-bit integers and replaces the first integer with the sum, as an atomic operation. |

Add(Int64, Int64) Add(Int64, Int64) Add(Int64, Int64) Add(Int64, Int64) |
Adds two 64-bit integers and replaces the first integer with the sum, as an atomic operation. |

## Add(Int32, Int32) Add(Int32, Int32) Add(Int32, Int32) Add(Int32, Int32)

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`

`Public Shared Function Add (ByRef location1 As Integer, value As Integer) As Integer`

#### Parameters

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

.

#### Returns

#### 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

## Add(Int64, Int64) Add(Int64, Int64) Add(Int64, Int64) Add(Int64, Int64)

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`

`Public Shared Function Add (ByRef location1 As Long, value As Long) As Long`

#### Parameters

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

.

#### Returns

#### 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