max

摘要

返回一组整数中的最大值。

语法

max(<integerList>)

说明

函数 max() 从整数数组或以逗号分隔的整数列表返回最大值。

示例

示例 1 - 从逗号分隔的整数列表中返回最大值

此配置返回整数列表中的最大数字。

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

示例 2 - 从整数数组返回最大值

此配置将回显作为对另一个资源实例的 引用 检索的整数数组的最大数字。 它使用 YAML 的折叠多行语法使函数更具可读性。

# max.example.2.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Echo integer array
  type: Test/Echo
  properties:
    output:
    - 3
    - 2
    - 5
    - 1
    - 7
- name: Echo maximum integer
  type: Test/Echo
  properties:
    output: >-
      [max(
        reference(
          resourceId('Test/Echo', 'Echo integer array')
        ).actualState.output
      )]
  dependsOn:
  - "[resourceId('Test/Echo', 'Echo integer array')]"
dsc config get --document max.example.2.dsc.config.yaml
results:
- name: Echo integer array
  type: Test/Echo
  result:
    actualState:
      output:
      - 3
      - 2
      - 5
      - 1
      - 7
- name: Echo maximum integer
  type: Test/Echo
  result:
    actualState:
      output: 7

参数

integerList

函数 max() 需要单个整数数组或逗号分隔的整数数组。 直接传递整数时,请用逗号分隔每个整数。 传递数组对象时,函数仅将单个数组作为参数。

Type:         [integer, array(integer)]
Required:     true
MinimumCount: 1
MaximumCount: 18446744073709551615

输出

max() 函数返回表示输入中最大值的单个整数。

Type: integer