Dart-programming-operators
Dartプログラミング-演算子
式は、値に評価される特別な種類のステートメントです。 すべての式はで構成されています-
- オペランド-データを表します
- 演算子-値を生成するためにオペランドを処理する方法を定義します。
次の式を考慮してください-「2 + 3」。 この式では、2と3は*オペランド*であり、記号 "+"(プラス)は*演算子*です。
この章では、Dartで使用できる演算子について説明します。
- 算術演算子
- 平等および関係演算子
- 型テスト演算子
- ビット演算子
- 割り当て演算子 *論理演算子
算術演算子
次の表に、Dartでサポートされている算術演算子を示します。
リンク:/dart_programming/dart_programming_arithmetic_operators [例を表示]
Sr.No | Operators & Meaning |
---|---|
1 |
Add |
2 |
− 引く |
3 |
-expr 単項マイナス、否定とも呼ばれます(式の符号を逆にします) |
4 | かける |
5 |
/ 割る |
6 |
~/ 除算、整数の結果を返します |
7 |
% 整数除算の剰余を取得(モジュロ) |
8 |
* * インクリメント |
9 |
-- デクリメント |
平等および関係演算子
関係演算子は、2つのエンティティ間の関係の種類をテストまたは定義します。 関係演算子はブール値、つまり 正誤。
Aの値が10で、Bが20であると仮定します。
リンク:/dart_programming/dart_programming_equality_relational_operators [例を表示]
Operator | Description | Example |
---|---|---|
> | Greater than | (A > B) is False |
< | Lesser than | (A < B) is True |
>= | Greater than or equal to | (A >= B) is False |
⇐ | Lesser than or equal to | (A ⇐ B) is True |
== | Equality | (A==B) is False |
!= | Not equal | (A!=B) is True |
型テスト演算子
これらの演算子は、実行時に型をチェックするのに便利です。
リンク:/dart_programming/dart_programming_type_test_operators [例を表示]
Operator | Meaning |
---|---|
is | True if the object has the specified type |
is! | False if the object has the specified type |
ビット演算子
次の表は、Dartで使用可能なビット演算子とその役割を示しています-
リンク:/dart_programming/dart_programming_bitwise_operators [例を表示]
Operator | Description | Example |
---|---|---|
Bitwise AND | a & b | Returns a one in each bit position for which the corresponding bits of both operands are ones. |
Bitwise OR | a | b |
Returns a one in each bit position for which the corresponding bits of either or both operands are ones. | Bitwise XOR | a ^ b |
Returns a one in each bit position for which the corresponding bits of either but not both operands are ones. | Bitwise NOT | ~ a |
Inverts the bits of its operand. | Left shift | a LT b |
Shifts a in binary representation b (< 32) bits to the left, shifting in zeroes from the right. | Signpropagating right shift | a GT b |
割り当て演算子
次の表に、Dartで使用可能な割り当て演算子を示します。
リンク:/dart_programming/dart_programming_assignment_operators [例を表示]
Sr.No | Operator & Description |
---|---|
1 |
=(Simple Assignment ) 右側のオペランドから左側のオペランドに値を割り当てます
|
2 |
??= 変数がnullの場合にのみ値を割り当てます |
3 |
+=(Add and Assignment) 右オペランドを左オペランドに追加し、結果を左オペランドに割り当てます。 例:C + = AはC = C + Aと同等 |
4 |
─=(Subtract and Assignment) 左のオペランドから右のオペランドを減算し、結果を左のオペランドに割り当てます。 例:C-= AはC = C – Aと同等 |
5 |
*=(Multiply and Assignment) 右オペランドと左オペランドを乗算し、結果を左オペランドに割り当てます。 例:C = AはC = C Aと同等 |
6 |
/=(Divide and Assignment) 左のオペランドを右のオペランドで除算し、結果を左のオペランドに割り当てます。 |
注-ビットごとの演算子にも同じロジックが適用されるため、&Lt; =、&Gt; =、&Gt; =、&Gt; =、| =および^ =になります。
論理演算子
論理演算子は、2つ以上の条件を結合するために使用されます。 論理演算子はブール値を返します。 変数Aの値が10で、Bが20であると仮定します。
リンク:/dart_programming/dart_programming_logical_operators [例を表示]
Operator | Description | Example |
---|---|---|
&& | And − The operator returns true only if all the expressions specified return true | (A > 10 && B > 10) is False. |
OR − The operator returns true if at least one of the expressions specified return true | (A > 10 | |
B > 10) is True. | ! | NOT − The operator returns the inverse of the expression’s result. For E.g.: !(7>5) returns false |
条件式
Dartには、ifelseステートメントを必要とする式を評価できる2つの演算子があります-
調子 ? expr1:expr2
条件が真の場合、式は expr1 を評価します(そしてその値を返します)。それ以外の場合は、 expr2 の値を評価して返します。
expr1 ?? expr2
例
次の例は、Dartで条件式を使用する方法を示しています-
それは次の出力を生成します-
例
別の例を見てみましょう-
それは次の出力を生成します-