概要
加入兩個整數,並傳回其總和。
語法
add(<operands>)
描述
函式會 add() 傳回兩個整數的總和。 它會將第二個操作數新增至第一個操作數。 您可以將的呼叫巢狀化, add() 以加總兩個以上的整數。
範例
範例 1 - 新增兩個整數
本範例文件說明如何使用 add() 函式傳回兩個整數的總和。
# add.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Sum of 3 and 5
type: Microsoft.DSC.Debug/Echo
properties:
output: "[add(3, 5)]"
dsc config get --file add.example.1.dsc.config.yaml
results:
- name: Sum of 3 and 5
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: 8
messages: []
hadErrors: false
範例 2 - 新增巢狀函式的輸出
此範例檔示範如何使用 add() 函式傳回傳回整數值的巢狀組態函數總和。
# add.example.2.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Add nested function outputs
type: Microsoft.DSC.Debug/Echo
properties:
output: "[add(mul(2,3), div(6,3))]"
dsc config get --file add.example.2.dsc.config.yaml
results:
- name: Add nested function outputs
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: 8
messages: []
hadErrors: false
參數
運算元
函 add() 式預期只有兩個整數做為輸入。
操作數可以是整數或傳回整數之任何組態函式的輸出。 以逗號分隔 操作 數 (,) 。
Type: integer
Required: true
MinimumCount: 2
MaximumCount: 2
輸出
函式會 add() 傳回代表 操作數總和的整數。
Type: integer