add

摘要

添加两个整数,返回其和。

语法

add(<operands>)

说明

函数 add() 返回两个整数之和。 它将第二个操作数添加到第一个操作数。 可以嵌套对 的 add() 调用,以求和两个以上的整数。

示例

示例 1 - 添加两个整数

此示例文档演示如何使用 add() 函数返回两个整数之和。

# add.example.1.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Sum of 3 and 5
  type: Test/Echo
  properties:
  output: "[add(3, 5)]"
dsc config get --document add.example.1.dsc.config.yaml 
results:
- name: Sum of 3 and 5
  type: Test/Echo
  result:
    actualState:
      output: 8
messages: []
hadErrors: false

示例 2 - 添加嵌套函数的输出

此示例文档演示如何使用 add() 函数返回返回整数值的嵌套配置函数的总和。

# add.example.2.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Add nested function outputs
  type: Test/Echo
  properties:
    output: "[add(mul(2,3), div(6,3))]"
dsc config get --document add.example.2.dsc.config.yaml
results:
- name: Add nested function outputs
  type: Test/Echo
  result:
    actualState:
      output: 8
messages: []
hadErrors: false

参数

操作数

函数 add() 需要恰好两个整数作为输入。 操作数可以是整数,也可以是返回整数的任何配置函数的输出。 使用逗号 () , 分隔操作数。

Type:         integer
Required:     true
MinimumCount: 2
MaximumCount: 2

输出

函数 add() 返回一个整数,表示 操作数之和

Type: integer