Cascade Notation Operators
This class of operators allows you to perform a sequence of operation on the same element. It allows you to perform multiple methods on the same object. It goes like this:
Operator Symbol | Operator Name | Operator Description |
---|---|---|
.. | Cascading Method | It is used to perform multiple methods on the same object. |
..? | Null Shorting Cascade | It is used when we are sure that the none of the cascade operations are done on Null elements. |
Example: Using Cascade Notation Operators in the program
// Dart Program to Demonstrate
// Use of Cascading Operator
// Class
class GFG {
var? a;
var? b;
void set(x, y)
{
this.a = x;
this.b = y;
}
void add()
{
var z = this.a + this.b;
print(z);
}
}
void main()
{
// Creating objects of class GFG
GFG geek1 = new GFG();
GFG geek2 = new GFG();
// Without using Cascade Notation
geek1.set(1, 2);
geek1.add();
// Using Cascade Notation
geek2..set(3, 4)
..add();
}
Output:
3
7
To know more about Dart please check Dart Tutorial
Operators in Dart
The operators are special symbols that are used to carry out certain operations on the operands. The Dart has numerous built-in operators which can be used to carry out different functions, for example, ‘+’ is used to add two operands. Operators are meant to carry operations on one or two operands.
Contact Us