Interlocked.Add 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將兩個整數相加,並將第一個整數替換為和,作為原子運算。
多載
| 名稱 | Description |
|---|---|
| Add(Int32, Int32) |
加入兩個 32 位元整數,並將第一個整數替換為和,作為原子運算。 |
| Add(Int64, Int64) |
加入兩個 64 位元整數,並將第一個整數替換為和,作為原子運算。 |
| Add(UInt32, UInt32) |
新增兩個 32 位元無符號整數,並將第一個整數替換為和,作為原子運算。 |
| Add(UInt64, UInt64) |
加入兩個 64 位元無符號整數,並將第一個整數替換為和,作為原子運算。 |
Add(Int32, Int32)
加入兩個 32 位元整數,並將第一個整數替換為和,作為原子運算。
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
包含第一個要加入的值的變數。 兩個值的和儲存在 location1。
- value
- Int32
在整數 location1處要加的值。
傳回
此操作所儲存 location1 的新值。
例外狀況
的 location1 位址是空指標。
備註
此方法處理溢位條件時,會繞行:若 在 的location1值為 Int32.MaxValuevalue 且為 1,則結果為 Int32.MinValue;若value為 2,則結果為 (Int32.MinValue+1);依此類推。 沒例外拋出。
另請參閱
- 管理的執行緒
- 同步處理基本概觀
適用於
Add(Int64, Int64)
加入兩個 64 位元整數,並將第一個整數替換為和,作為原子運算。
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
包含第一個要加入的值的變數。 兩個值的和儲存在 location1。
- value
- Int64
在整數 location1處要加的值。
傳回
此操作所儲存 location1 的新值。
例外狀況
的 location1 位址是空指標。
備註
此方法處理溢位條件時,會繞行:若 在 的location1值為 Int64.MaxValuevalue 且為 1,則結果為 Int64.MinValue;若value為 2,則結果為 (Int64.MinValue+1);依此類推。 沒例外拋出。
另請參閱
- Increment
- Decrement
- Read(Int64)
- 管理的執行緒
- 同步處理基本概觀
適用於
Add(UInt32, UInt32)
重要
此 API 不符合 CLS 規範。
新增兩個 32 位元無符號整數,並將第一個整數替換為和,作為原子運算。
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
參數
- location1
- UInt32
包含第一個要加入的值的變數。 兩個值的和儲存在 location1。
- value
- UInt32
在整數 location1處要加的值。
傳回
此操作所儲存 location1 的新值。
- 屬性
例外狀況
的 location1 位址是一個 null 指標。
適用於
Add(UInt64, UInt64)
重要
此 API 不符合 CLS 規範。
加入兩個 64 位元無符號整數,並將第一個整數替換為和,作為原子運算。
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
參數
- location1
- UInt64
包含第一個要加入的值的變數。 兩個值的和儲存在 location1。
- value
- UInt64
在整數 location1處要加的值。
傳回
此操作所儲存 location1 的新值。
- 屬性
例外狀況
的 location1 位址是一個 null 指標。