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

Add(UInt64, UInt64) |

## 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 -> 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 stored at `location1`

.

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

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 stored at `location1`

.

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

## Add(UInt32, UInt32)

Important

This API is not CLS-compliant.

```
public:
static System::UInt32 Add(System::UInt32 % location1, System::UInt32 value);
```

```
[System.CLSCompliant(false)]
public static uint Add (ref uint location1, uint value);
```

`static member Add : uint32 * uint32 -> uint32`

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

#### Parameters

- location1
- UInt32

- value
- UInt32

#### Returns

- Attributes

## Add(UInt64, UInt64)

Important

This API is not CLS-compliant.

```
public:
static System::UInt64 Add(System::UInt64 % location1, System::UInt64 value);
```

```
[System.CLSCompliant(false)]
public static ulong Add (ref ulong location1, ulong value);
```

`static member Add : uint64 * uint64 -> uint64`

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

#### Parameters

- location1
- UInt64

- value
- UInt64

#### Returns

- Attributes