Bicep の比較演算子

比較演算子を使用すると、値が比較され、true または false のいずれかが返されます。 この例を実行するには、Azure CLI または Azure PowerShell を使用して、Bicep ファイルをデプロイします。

演算子 Name
>= [次の値以上]
> より大きい
<= [次の値以下]
< 次の値より小さい
== [等しい]
!= 等しくない
=~ 大文字と小文字の区別を無視し、等しい
!~ 大文字と小文字の区別を無視し、等しくない

以上 >=

operand1 >= operand2

1 番目の値が 2 番目の値以上かどうかを評価します。

オペランド

オペランド 種類 説明
operand1 整数、文字列 比較の 1 番目の値。
operand2 整数、文字列 比較の 2 番目の値。

戻り値

1 番目の値が 2 番目の値以上の場合は、true が返されます。 それ以外の場合は、false が返されます。

整数のペアと文字列のペアを比較します。

param firstInt int = 10
param secondInt int = 5

param firstString string = 'A'
param secondString string = 'A'

output intGtE bool = firstInt >= secondInt
output stringGtE bool = firstString >= secondString

例の出力を次に示します。

名前 Type
intGtE boolean true
stringGtE boolean true

大なり >

operand1 > operand2

1 番目の値が 2 番目の値より大きいかどうかを評価します。

オペランド

オペランド 種類 説明
operand1 整数、文字列 比較の 1 番目の値。
operand2 整数、文字列 比較の 2 番目の値。

戻り値

1 番目の値が 2 番目の値より大きい場合は、true が返されます。 それ以外の場合は、false が返されます。

整数のペアと文字列のペアを比較します。

param firstInt int = 10
param secondInt int = 5

param firstString string = 'bend'
param secondString string = 'band'

output intGt bool = firstInt > secondInt
output stringGt bool = firstString > secondString

例の出力を次に示します。

bend に含まれる e により、1 つ目の文字列の方が大きくなります。

Name Type
intGt boolean true
stringGt boolean true

以下 <=

operand1 <= operand2

1 番目の値が 2 番目の値以下かどうかを評価します。

オペランド

オペランド 種類 説明
operand1 整数、文字列 比較の 1 番目の値。
operand2 整数、文字列 比較の 2 番目の値。

戻り値

1 番目の値が 2 番目の値以下の場合は、true が返されます。 それ以外の場合は、false が返されます。

整数のペアと文字列のペアを比較します。

param firstInt int = 5
param secondInt int = 10

param firstString string = 'demo'
param secondString string = 'demo'

output intLtE bool = firstInt <= secondInt
output stringLtE bool = firstString <= secondString

例の出力を次に示します。

名前 Type
intLtE boolean true
stringLtE boolean true

小なり <

operand1 < operand2

1 番目の値が 2 番目の値より小さいかどうかを評価します。

オペランド

オペランド 種類 説明
operand1 整数、文字列 比較の 1 番目の値。
operand2 整数、文字列 比較の 2 番目の値。

戻り値

1 番目の値が 2 番目の値より小さい場合は、true が返されます。 それ以外の場合は、false が返されます。

整数のペアと文字列のペアを比較します。

param firstInt int = 5
param secondInt int = 10

param firstString string = 'demo'
param secondString string = 'Demo'

output intLt bool = firstInt < secondInt
output stringLt bool = firstString < secondString

例の出力を次に示します。

小文字は大文字よりも小さいので、文字列は true です。

Name Type
intLt boolean true
stringLt boolean true

等しい ==

operand1 == operand2

値が等しいかどうかを評価します。 比較では、大文字と小文字を区別します。

オペランド

オペランド 種類 説明
operand1 文字列、整数、ブール値、配列、オブジェクト 比較の 1 番目の値。
operand2 文字列、整数、ブール値、配列、オブジェクト 比較の 2 番目の値。

戻り値

オペランドが等しい場合は、true が返されます。 オペランドが異なる場合は、false が返されます。

整数、文字列、ブール値のペアが比較されます。

param firstInt int = 5
param secondInt int = 5

param firstString string = 'demo'
param secondString string = 'Demo'

param firstBool bool = true
param secondBool bool = true

output intEqual bool = firstInt == secondInt
output stringEqual bool = firstString == secondString
output boolEqual bool = firstBool == secondBool

例の出力を次に示します。

名前 Type Value Note
intEqual boolean true
stringEqual boolean false 比較では大文字と小文字が区別されるため、結果は false
boolEqual boolean true

配列を比較する場合、2 つの配列の要素と順序は同じである必要があります。 配列を互いに割り当てる必要はありません。

var array1 = [
  1
  2
  3
]

var array2 = [
  1
  2
  3
]

var array3 = array2

var array4 = [
  3
  2
  1
]

output sameElements bool = array1 == array2 // returns true because arrays are defined with same elements
output assignArray bool = array2 == array3 // returns true because one array was defined as equal to the other array
output differentOrder bool = array4 == array1 // returns false because order of elements is different

例の出力を次に示します。

名前 Type
sameElements bool true
assignArray bool true
differentOrder [bool] false

オブジェクトを比較する場合、プロパティ名と値は同じである必要があります。 プロパティを同じ順序で定義する必要はありません。

var object1 = {
  prop1: 'val1'
  prop2: 'val2'
}

var object2 = {
  prop1: 'val1'
  prop2: 'val2'
}

var object3 = {
  prop2: 'val2'
  prop1: 'val1'
}

var object4 = object3

var object5 = {
  prop1: 'valX'
  prop2: 'valY'
}

output sameObjects bool = object1 == object2 // returns true because both objects defined with same properties
output differentPropertyOrder bool = object3 == object2 // returns true because both objects have same properties even though order is different
output assignObject bool = object4 == object1 // returns true because one object was defined as equal to the other object
output differentValues bool = object5 == object1 // returns false because values are different

例の出力を次に示します。

名前 Type
sameObjects bool true
differentPropertyOrder bool true
assignObject bool true
differentValues [bool] false

等しくない !=

operand1 != operand2

2 つの値が等しくないかどうかを評価します。

オペランド

オペランド 種類 説明
operand1 文字列、整数、ブール値、配列、オブジェクト 比較の 1 番目の値。
operand2 文字列、整数、ブール値、配列、オブジェクト 比較の 2 番目の値。

戻り値

オペランドが等しくない場合は、true が返されます。 オペランドが等しい場合は、false が返されます。

整数、文字列、ブール値のペアが比較されます。

param firstInt int = 10
param secondInt int = 5

param firstString string = 'demo'
param secondString string = 'test'

param firstBool bool = false
param secondBool bool = true

output intNotEqual bool = firstInt != secondInt
output stringNotEqual bool = firstString != secondString
output boolNotEqual bool = firstBool != secondBool

例の出力を次に示します。

名前 Type
intNotEqual boolean true
stringNotEqual boolean true
boolNotEqual boolean true

配列とオブジェクトについては、「等しい」の例を参照してください。

大文字と小文字の区別を無視し、等しい =~

operand1 =~ operand2

大文字と小文字の区別を無視して、2 つの値が等しいかどうかを判定します。

オペランド

オペランド 種類 説明
operand1 string 比較の 1 番目の文字列。
operand2 string 比較の 2 番目の文字列。

戻り値

文字列が等しい場合は、true が返されます。 それ以外の場合は、false が返されます。

大文字と小文字が混在した文字列を比較します。

param firstString string = 'demo'
param secondString string = 'DEMO'

param thirdString string = 'demo'
param fourthString string = 'TEST'

output strEqual1 bool = firstString =~ secondString
output strEqual2 bool = thirdString =~ fourthString

例の出力を次に示します。

名前 Type
strEqual1 boolean true
strEqual2 boolean false

大文字と小文字の区別を無視し、等しくない !~

operand1 !~ operand2

大文字と小文字の区別を無視して、2 つの値が等しくないかどうかを判定します。

オペランド

オペランド 種類 説明
operand1 string 比較の 1 番目の文字列。
operand2 string 比較の 2 番目の文字列。

戻り値

文字列が等しくない場合は、true が返されます。 それ以外の場合は、false が返されます。

大文字と小文字が混在した文字列を比較します。

param firstString string = 'demo'
param secondString string = 'TEST'

param thirdString string = 'demo'
param fourthString string = 'DeMo'

output strNotEqual1 bool = firstString !~ secondString
output strEqual2 bool = thirdString !~ fourthString

例の出力を次に示します。

名前 Type
strNotEqual1 boolean true
strNotEqual2 boolean false

次のステップ