概要
從一組整數傳回最大值。
語法
max(<integerList>)
描述
函 max() 式會從整數陣列或以逗號分隔的整數清單傳回最大值。
範例
範例 1 - 從以逗號分隔的整數列表傳回最大值
此組態會從整數清單中傳回最大數目。
# max.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Echo maximum value
type: Microsoft.DSC.Debug/Echo
properties:
output: "[max(3, 2, 5, 1, 7)]"
dsc config get --file max.example.1.dsc.config.yaml config get
results:
- name: Echo maximum value
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: 7
messages: []
hadErrors: false
範例 2 - 從整數陣列傳回最大值
此組態會從擷取為另一個資源實例 參考 的整數數位回應最大數目。 它會使用 YAML 的折疊多行語法,讓函式更容易閱讀。
# max.example.2.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Echo integer array
type: Microsoft.DSC.Debug/Echo
properties:
output:
- 3
- 2
- 5
- 1
- 7
- name: Echo maximum integer
type: Microsoft.DSC.Debug/Echo
properties:
output: >-
[max(
reference(
resourceId('Microsoft.DSC.Debug/Echo', 'Echo integer array')
).actualState.output
)]
dependsOn:
- "[resourceId('Microsoft.DSC.Debug/Echo', 'Echo integer array')]"
dsc config get --file max.example.2.dsc.config.yaml
results:
- name: Echo integer array
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
- 3
- 2
- 5
- 1
- 7
- name: Echo maximum integer
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: 7
參數
integerList
函 max() 式需要整數的單一陣列或以逗號分隔的整數陣列。 當您直接傳遞整數時,請以逗號分隔每個整數。 當您傳遞陣列物件時,函式只會接受單一陣列做為自變數。
Type: [integer, array(integer)]
Required: true
MinimumCount: 1
MaximumCount: 18446744073709551615
輸出
函式會 max() 傳回代表輸入中最大值的單一整數。
Type: integer