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

定義

將兩個整數相加,並以總和取代第一個整數,成為不可部分完成的作業。Adds two 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)

將兩個 32 位元整數加相,並以總和取代第一個整數,成為不可部分完成的作業。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)

將兩個 64 位元整數加相,並以總和取代第一個整數,成為不可部分完成的作業。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)

將兩個 32 位元整數加相,並以總和取代第一個整數,成為不可部分完成的作業。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

參數

location1
Int32 Int32 Int32 Int32

包含要加入的第一個值的變數。A variable containing the first value to be added. 這兩個值的總和會存放在 location1 中。The sum of the two values is stored in location1.

value
Int32 Int32 Int32 Int32

要加入 location1 的整數的值。The value to be added to the integer at location1.

傳回

新值儲存於 location1The new value stored at location1.

例外狀況

location1 的位址為 null 指標。The address of location1 is a null pointer.

備註

這個方法會藉由包裝來處理溢位條件:如果location1Int32.MaxValuevalue是,而是1, Int32.MinValue則結果value是; 如果為2,則Int32.MinValue結果會是(+ 1); 依此類推。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.

另請參閱

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

將兩個 64 位元整數加相,並以總和取代第一個整數,成為不可部分完成的作業。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

參數

location1
Int64 Int64 Int64 Int64

包含要加入的第一個值的變數。A variable containing the first value to be added. 這兩個值的總和會存放在 location1 中。The sum of the two values is stored in location1.

value
Int64 Int64 Int64 Int64

要加入 location1 的整數的值。The value to be added to the integer at location1.

傳回

新值儲存於 location1The new value stored at location1.

例外狀況

location1 的位址為 null 指標。The address of location1 is a null pointer.

備註

這個方法會藉由包裝來處理溢位條件:如果location1Int64.MaxValuevalue是,而是1, Int64.MinValue則結果value是; 如果為2,則Int64.MinValue結果會是(+ 1); 依此類推。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.

另請參閱

適用於