Arithmetic Operators: +, -, *, /, ~/ (integer division), %.
Increment and Decrement Operators: ++, -- ++pre, post++, --pre, post--
Relational Operators: ==, !=, >, <, >=, <=
Logical Operators: && (AND), || (OR), ! (NOT).
Bitwise Operators: &, |, ^, ~, << (left shift), >> (right shift).
Assignment Operators: =, +=, -=, *=, /=, ~/=, %=.
Conditional (Ternary) Operator: condition ? expr1 : expr2.
Null-aware Operators: ??, ??=.
Type Test Operators: is, is!.
Parse Operator
void main() {
// Arithmetic Operators
int a = 10;
int b = 3;
print("a + b = ${a + b}"); // Addition
print("a - b = ${a - b}"); // Subtraction
print("a * b = ${a * b}"); // Multiplication
print("a / b = ${a / b}"); // Division (returns double)
print("a ~/ b = ${a ~/ b}"); // Integer Division
print("a % b = ${a % b}"); // Modulus
// Increment and Decrement Operators
int x = 5;
print("++x = ${++x}"); // Pre-increment
print("x++ = ${x++}"); // Post-increment
print("x after x++ = $x");
int y = 5;
print("--y = ${--y}"); // Pre-decrement
print("y-- = ${y--}"); // Post-decrement
print("y after y-- = $y");
print("a == b: ${a == b}"); // Equality
print("a != b: ${a != b}"); // Inequality
print("a > b: ${a > b}"); // Greater than
print("a < b: ${a < b}"); // Less than
print("a >= b: ${a >= b}"); // Greater than or equal to
print("a <= b: ${a <= b}"); // Less than or equal to
// Logical Operators
bool isTrue = true;
bool isFalse = false;
print("isTrue && isFalse: ${isTrue && isFalse}"); // AND
print("isTrue || isFalse: ${isTrue || isFalse}"); // OR
print("!isTrue: ${!isTrue}"); // NOT
// Bitwise Operators
int bitwiseA = 5; // 0101 in binary
int bitwiseB = 3; // 0011 in binary
print("bitwiseA & bitwiseB: ${bitwiseA & bitwiseB}"); // AND
print("bitwiseA | bitwiseB: ${bitwiseA | bitwiseB}"); // OR
print("bitwiseA ^ bitwiseB: ${bitwiseA ^ bitwiseB}"); // XOR
print("~bitwiseA: ${~bitwiseA}"); // NOT
print("bitwiseA << 1: ${bitwiseA << 1}"); // Left Shift
print("bitwiseB >> 1: ${bitwiseB >> 1}"); // Right Shift
// Assignment Operators
int c = 10;
c += 5; // c = c + 5
print("c += 5: $c");
c -= 3; // c = c - 3
print("c -= 3: $c");
c *= 2; // c = c * 2
print("c *= 2: $c");
c ~/= 2; // c = c ~/ 2 (integer division)
print("c ~/= 2: $c");
c %= 3; // c = c % 3
print("c %= 3: $c");
// Conditional (Ternary) Operator
int age = 18;
String eligibility = (age >= 18) ? "Eligible" : "Not Eligible";
print("Eligibility: $eligibility");
// Null-aware Operators
String? name;
print("name ?? 'Guest': ${name ?? 'Guest'}"); // If name is null, use 'Guest'
name ??= "Alice"; // Assign 'Alice' to name if it is null
print("name after ??= : $name");
// Type Test Operators
var number = 123;
print("number is int: ${number is int}"); // True if number is an int
print("number is! String: ${number is! String}"); // True if number is NOT a String
}
void main() {
int a = 10, b = 20;
int sum = a + b;
print("Sum: $sum");
}
void main() {
int a = 30, b = 15;
int difference = a - b;
print("Difference: $difference");
}
void main() {
int a = 7, b = 6;
int product = a * b;
print("Product: $product");
}
void main() {
double a = 22, b = 7;
double quotient = a / b;
print("Quotient: $quotient");
}
void main() {
int a = 17, b = 5;
int remainder = a % b;
print("Remainder: $remainder");
}
void main() {
int a = 17, b = 5;
int quotient = a ~/ b;
print("Quotient (integer division): $quotient");
}
void main() {
int a = 10;
a++;
print("Incremented Value: $a");
}
void main() {
int a = 10;
a--;
print("Decremented Value: $a");
}
void main() {
int length = 10, width = 5;
int perimeter = 2 * (length + width);
print("Perimeter: $perimeter");
}
void main() {
double radius = 7;
double area = 3.14 * radius * radius;
print("Area of Circle: $area");
}
void main() {
int a = 5, b = 10;
a = a + b;
b = a - b;
a = a - b;
print("After swapping: a = $a, b = $b");
}
void main() {
int number = 1234;
int sum = 0;
while (number > 0) {
sum += number % 10;
number ~/= 10;
}
print("Sum of digits: $sum");
}
void main() {
double principal = 1000, rate = 5, time = 2;
double amount = principal * (1 + (rate / 100)) * time;
print("Compound Interest: ${amount - principal}");
}
void main() {
double a = 4, b = 7, c = 9, d = 12, e = 15;
double average = (a + b + c + d + e) / 5;
print("Average: $average");
}
void main() {
int number = 15;
print(number % 2 == 0 ? "Even" : "Odd");
}
void main() {
double celsius = 25;
double fahrenheit = (celsius * 9 / 5) + 32;
print("$celsius°C = $fahrenheit°F");
}
void main() {
int number = 12345, reverse = 0;
while (number != 0) {
reverse = reverse * 10 + number % 10;
number ~/= 10;
}
print("Reversed Number: $reverse");
}
void main() {
double weight = 70; // in kg
double height = 1.75; // in meters
double bmi = weight / (height * height);
print("BMI: $bmi");
}
import 'dart:math';
void main() {
int base = 2, exponent = 3;
int power = pow(base, exponent) as int;
print("$base^$exponent = $power");
}
void main() {
int year = 2024;
print((year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? "Leap Year" : "Not a Leap Year");
}
void main()
{
var n=1, m=2;
print('n+m=${n+m}');
print('n-m=${n-m}');
print('n*m=${n*m}');
print('n/m=${n/m}');
print('n%m=${n%m}');
}
void main() {
int a = 10;
int b = 3;
print('Addition: ${a + b}'); // 13
print('Subtraction: ${a - b}'); // 7
print('Multiplication: ${a * b}'); // 30
print('Division: ${a / b}'); // 3.3333
print('Integer Division: ${a ~/ b}'); // 3
print('Modulus: ${a % b}'); // 1
}
void main()
{
int a=1; //assign
int b=1;
a=a+1; //increese and assign
b+=1;
print(a);
print(b);
}
void main() {
int z = 5;
z += 3; // z = z + 3
print('After += : $z'); // 8
z -= 2; // z = z - 2
print('After -= : $z'); // 6
z *= 2; // z = z * 2
print('After *= : $z'); // 12
z ~/= 3; // z = z ~/ 3
print('After ~/= : $z'); // 4
z %= 2; // z = z % 2
print('After %= : $z'); // 0
}
Assignment operators in Dart are used to assign values to variables. Apart from the basic assignment operator (=), Dart supports compound assignment operators like +=, -=, *=, /=, %=, and others. Here are 10 programs demonstrating various assignment operators:
void main() {
int number = 10; // Assign 10 to number
print("The value of number is: $number");
}
Output:
The value of number is: 10
void main() {
int number = 5;
number += 10; // Add 10 to number
print("The value of number is: $number");
}
Output
The value of number is: 15
void main() {
int number = 20;
number -= 5; // Subtract 5 from number
print("The value of number is: $number");
}
Output:
The value of number is: 15
void main() {
int number = 4;
number *= 3; // Multiply number by 3
print("The value of number is: $number");
}
Output:
The value of number is: 12
void main() {
double number = 15;
number /= 3; // Divide number by 3
print("The value of number is: $number");
}
Outpu
The value of number is: 5.0
void main() {
int number = 17;
number %= 3; // Assign remainder of number divided by 3
print("The value of number is: $number");
}
Output:
The value of number is: 2
void main() {
int number = 2;
number <<= 2; // Shift bits of number 2 positions to the left
print("The value of number is: $number");
}
Output:
The value of number is: 8
void main() {
int number = 16;
number >>= 2; // Shift bits of number 2 positions to the right
print("The value of number is: $number");
}
Output:
The value of number is: 4
void main() {
int number = 12; // 1100 in binary
number &= 5; // 0101 in binary
print("The value of number is: $number"); // Bitwise AND result
}
Output:
The value of number is: 4
dart
Copy code
void main() {
int? number; // Variable is null initially
number ??= 10; // Assign 10 only if number is null
print("The value of number is: $number");
}
Output:
csharp
Copy code
The value of number is: 10
void main()
{
bool a=false, b=true;
print(a&b);
print(a|b);
// print(~a); Error
print(a^b);
// print(a>>b); Error
// print(a<<b);
}
Logical operators in Dart are used to combine or invert boolean expressions. The primary logical operators are:
&& (Logical AND)
|| (Logical OR)
! (Logical NOT)
Here are 10 example programs to demonstrate the use of logical operators in Dart:
void main() {
bool isAdult = true;
bool hasID = true;
if (isAdult && hasID) {
print("You can enter the club.");
} else {
print("Entry denied.");
}
}
Output:
You can enter the club.
void main() {
bool hasPassport = false;
bool hasVisa = true;
if (hasPassport || hasVisa) {
print("You can travel internationally.");
} else {
print("Travel restricted.");
}
}
Output:
You can travel internationally.
void main() {
bool isSunny = false;
if (!isSunny) {
print("It is not sunny today.");
} else {
print("It is sunny today.");
}
}
Output:
It is not sunny today.
void main() {
int age = 20;
bool hasParentalConsent = true;
if ((age >= 18 && age <= 21) || hasParentalConsent) {
print("You can participate in the activity.");
} else {
print("You cannot participate.");
}
}
Output:
You can participate in the activity.
void main() {
String? name = null;
if (!(name != null)) {
print("Name is null.");
} else {
print("Name is not null.");
}
}
Output:
Name is null.
void main() {
int marks = 85;
if (marks > 70 && marks < 90) {
print("You scored a B grade.");
} else {
print("You scored another grade.");
}
}
Output:
You scored a B grade.
void main() {
bool isCitizen = true;
bool hasVoterID = false;
if (isCitizen || hasVoterID) {
print("You are eligible to vote.");
} else {
print("You are not eligible to vote.");
}
}
Output:
You are eligible to vote.
void main() {
int count = 0;
while (count < 5 && count >= 0) {
print("Count is: $count");
count++;
}
}
Output:
Count is: 0
Count is: 1
Count is: 2
Count is: 3
Count is: 4
void main() {
int temperature = 25;
bool isRaining = false;
bool isSnowing = false;
if ((temperature > 20 && temperature < 30) && (!isRaining && !isSnowing)) {
print("The weather is perfect for hiking.");
} else {
print("The weather is not suitable for hiking.");
}
}
Output:
The weather is perfect for hiking.
void main() {
int age = 16;
bool hasPermission = true;
bool isWeekend = false;
if ((age >= 18 || hasPermission) && isWeekend) {
print("You can attend the event.");
} else {
print("You cannot attend the event.");
}
}
Output:
You cannot attend the event.
In Dart, increment (++) and decrement (--) operators are used to increase or decrease the value of a variable by 1. These operators can be used in two forms: prefix (++var, --var) and postfix (var++, var--). Below are five example programs to demonstrate their usage.
void main() {
int number = 5;
print("Initial value: $number");
print("Value after postfix increment: ${number++}");
print("Value now: $number");
}
Output:
Initial value: 5
Value after postfix increment: 5
Value now: 6
void main() {
int number = 5;
print("Initial value: $number");
print("Value after prefix increment: ${++number}");
print("Value now: $number");
}
Output:
Initial value: 5
Value after prefix increment: 6
Value now: 6
void main() {
int number = 10;
print("Initial value: $number");
print("Value after postfix decrement: ${number--}");
print("Value now: $number");
}
Output:
Initial value: 10
Value after postfix decrement: 10
Value now: 9
void main() {
int number = 10;
print("Initial value: $number");
print("Value after prefix decrement: ${--number}");
print("Value now: $number");
}
Output:
Initial value: 10
Value after prefix decrement: 9
Value now: 9
void main() {
int count = 0;
print("Counting up:");
while (count < 5) {
print(++count); // Prefix increment
}
print("Counting down:");
while (count > 0) {
print(count--); // Postfix decrement
}
}
Output:
Counting up:
1
2
3
4
5
Counting down:
5
4
3
2
1
void main()
{
var x=null;
var y=9;
var z;
var p=22;
var val=x??y;
var val2=y??z;
var val3=p??y;
print(val);
print(val2);
print(val3);
}
EX-
void main()
{
var a=39;
var output=a>38?"Greater than 38":"Lesser than 38";
print(output);
}
EX=
void main() {
int score = 75;
String result = (score >= 50) ? 'Pass' : 'Fail';
print('Result: $result'); // Pass
}
In Dart, increment (++) and decrement (--) operators are used to increase or decrease the value of a variable by 1. These operators can be used in two forms: prefix (++var, --var) and postfix (var++, var--). Below are five example programs to demonstrate their usage.
void main() {
int number = 5;
print("Initial value: $number");
print("Value after postfix increment: ${number++}");
print("Value now: $number");
}
Output:
Initial value: 5
Value after postfix increment: 5
Value now: 6
void main() {
int number = 5;
print("Initial value: $number");
print("Value after prefix increment: ${++number}");
print("Value now: $number");
}
Output:
Initial value: 5
Value after prefix increment: 6
Value now: 6
void main() {
int number = 10;
print("Initial value: $number");
print("Value after postfix decrement: ${number--}");
print("Value now: $number");
}
Output:
Initial value: 10
Value after postfix decrement: 10
Value now: 9
void main() {
int number = 10;
print("Initial value: $number");
print("Value after prefix decrement: ${--number}");
print("Value now: $number");
}
Output:
Initial value: 10
Value after prefix decrement: 9
Value now: 9
void main() {
int count = 0;
print("Counting up:");
while (count < 5) {
print(++count); // Prefix increment
}
print("Counting down:");
while (count > 0) {
print(count--); // Postfix decrement
}
}
Output:
Counting up:
1
2
3
4
5
Counting down:
5
4
3
2
1
void main() {
int x = 5;
int y = 10;
print('Is x greater than y? ${x > y}'); // false
print('Is x less than or equal to y? ${x <= y}'); // true
print('Is x equal to y? ${x == y}'); // false
print('Is x not equal to y? ${x != y}'); // true
}
void main() {
int a = 10;
int b = 20;
print("Is a > b? ${a > b}"); // Greater than
print("Is a < b? ${a < b}"); // Less than
}
Output:
Is a > b? false
Is a < b? true
void main() {
double x = 15.5;
double y = 15.5;
print("Is x >= y? ${x >= y}"); // Greater than or equal
print("Is x <= y? ${x <= y}"); // Less than or equal
}
Output:
Is x >= y? true
Is x <= y? true
void main() {
String str1 = "Dart";
String str2 = "Flutter";
print("Is str1 == str2? ${str1 == str2}"); // Equality
print("Is str1 != str2? ${str1 != str2}"); // Inequality
}
Output:
Is str1 == str2? false
Is str1 != str2? true
void main() {
int age = 18;
if (age >= 18) {
print("You are eligible to vote.");
} else {
print("You are not eligible to vote.");
}
}
Output:
You are eligible to vote.
void main() {
int num1 = 50;
int num2 = 30;
int num3 = 50;
print("Is num1 > num2? ${num1 > num2}");
print("Is num1 < num2? ${num1 < num2}");
print("Is num1 == num3? ${num1 == num3}");
}
Output:
Is num1 > num2? true
Is num1 < num2? false
Is num1 == num3? true
void main() {
dynamic variable = 'Hello';
print(variable is String); // true
print(variable is! int); // true
}
Ex=
void main()
{
int a=33;
double b=2.2;
String c="san";
print( a is int);
print(b is int);
print(c is! String);
}
In Dart, null-aware operators help you handle null values gracefully without running into exceptions. Below are five examples showcasing various null-aware operators:
The ?? operator provides a default value if the expression on the left evaluates to null.
void main() {
String? name;
String greeting = name ?? "Guest"; // Default value if name is null
print("Hello, $greeting!");
}
Output:
Hello, Guest!
The ?. operator allows you to call a method or access a property on an object only if it’s not null.
class Person {
String? name;
void sayHello() {
print("Hello from $name!");
}
}
void main() {
Person? person;
person?.sayHello(); // Safe, won't throw an error even if person is null
}
Output:
(no output since `person` is null)
The ??= operator assigns a value to a variable only if it is currently null.
void main() {
int? number;
number ??= 42; // Assign 42 only if number is null
print("The number is: $number");
}
Output:
The number is: 42
Use both ?. and ?? together to safely access properties and provide defaults.
class Address {
String? city;
}
class User {
Address? address;
}
void main() {
User? user = User();
String city = user?.address?.city ?? "Unknown City";
print("User lives in: $city");
}
Output:
User lives in: Unknown City
You can safely access elements in a nullable list using the []? operator.
void main() {
List<String>? fruits = ["Apple", "Banana", "Cherry"];
String? fruit = fruits?[1]; // Access second item if the list is not null
print("Selected fruit: $fruit");
}
Output:
Selected fruit: Banana
In Dart, the parse method is used to convert a string into a number (int or double). Below are five example programs to demonstrate its usage and various scenarios.
void main() {
String numberString = "123";
int number = int.parse(numberString);
print("The integer value is: $number");
}
Output:
The integer value is: 123
void main() {
String decimalString = "45.67";
double decimal = double.parse(decimalString);
print("The double value is: $decimal");
}
Output:
The double value is: 45.67
void main() {
String invalidNumber = "123abc";
try {
int number = int.parse(invalidNumber);
print("Parsed number is: $number");
} catch (e) {
print("Error: Unable to parse '$invalidNumber' into an integer.");
}
}
Output:
Error: Unable to parse '123abc' into an integer.
tryParse returns null instead of throwing an error if parsing fails.
void main() {
String invalidNumber = "123abc";
int? number = int.tryParse(invalidNumber);
if (number == null) {
print("Parsing failed. '$invalidNumber' is not a valid number.");
} else {
print("Parsed number is: $number");
}
}
Output:
Parsing failed. '123abc' is not a valid number.
void main() {
String firstNumber = "10";
String secondNumber = "20";
int num1 = int.parse(firstNumber);
int num2 = int.parse(secondNumber);
int sum = num1 + num2;
print("The sum of $num1 and $num2 is: $sum");
}
Output:
The sum of 10 and 20 is: 30
The cascade operator (..) in Dart allows you to make multiple method calls or property assignments on the same object without repeating its name. Below are five examples showcasing the usage of the cascade operator in Dart programming.
Set multiple properties of an object in a single statement.
class Car {
String? make;
String? model;
int? year;
void displayDetails() {
print("Car: $make $model, Year: $year");
}
}
void main() {
Car car = Car()
..make = "Toyota"
..model = "Camry"
..year = 2023
..displayDetails(); // Display car details
}
Output:
Car: Toyota Camry, Year: 2023
Call multiple methods on the same object.
class Printer {
void printTitle(String title) => print("Title: $title");
void printAuthor(String author) => print("Author: $author");
void printYear(int year) => print("Year: $year");
}
void main() {
Printer()
..printTitle("Dart Programming")
..printAuthor("John Doe")
..printYear(2024);
}
Output:
Title: Dart Programming
Author: John Doe
Year: 2024
The cascade operator can be used to manipulate collections.
void main() {
List<int> numbers = []
..add(10)
..add(20)
..add(30)
..addAll([40, 50]);
print("Numbers: $numbers");
}
Output:
Numbers: [10, 20, 30, 40, 50]
Combine cascades with constructors for cleaner initialization.
class Book {
String? title;
String? author;
int? year;
void showDetails() {
print("Book: $title, Author: $author, Year: $year");
}
}
void main() {
Book()
..title = "Flutter for Beginners"
..author = "Jane Doe"
..year = 2023
..showDetails();
}
Output:
Book: Flutter for Beginners, Author: Jane Doe, Year: 2023
Use cascades on nested objects for complex initialization.
class Engine {
String? type;
int? horsepower;
}
class Vehicle {
String? name;
Engine? engine;
void showDetails() {
print("Vehicle: $name, Engine: ${engine?.type}, Horsepower: ${engine?.horsepower}");
}
}
void main() {
Vehicle vehicle = Vehicle()
..name = "Sports Car"
..engine = (Engine()
..type = "V8"
..horsepower = 500)
..showDetails();
}
Output:
Vehicle: Sports Car, Engine: V8, Horsepower: 500
void main() //This operator allows you to make multiple calls on the same object.
{
StringBuffer sb = StringBuffer();
sb
..write('Hello, ')
..write('world!')
..write(' Dart is great.');
print(sb.toString()); // Hello, world! Dart is great.
}
void main()
{
int a=10, b=5;
print('a+b= ${a+b}'); //Arithmentic operators
print('a-b= ${a-b}');
print('a*b= ${a*b}');
print('a/b= ${a/b}');
print('a%b= ${a%b}');
print('a~/b= ${a~/b}');
print('a==b: ${a==b}'); //Equality
print('a!=b: ${a==b}'); //relational
print('a>b: ${a>b}');
print('a<b: ${a<b}');
print('a>=b: ${a>=b}');
print('a<=b: ${a<=b}');
bool x=true, y=false; //Logical
print('x&&y: ${x&&y}'); //and
print('x||y: ${x||y}'); //or
print('!y: ${!y}'); //not
int d=0, c=1; //Bitwise
print('c&d: ${c&d}'); //and
print('c|d: ${c|d}'); //or
int e=5, f=5; //assignment
e=e+2;
f+=2;
print('e=$e, f=$f');
e=e++; //increment
print('e++= $e');
}
Addition
Subtraction
Multiplication
Division
Integer Division
Modulus
Equal To
void main() {
int a = 5, b = 5;
print('Equal: ${a == b}');
}
Not Equal
void main() {
int a = 5, b = 6;
print('Not Equal: ${a != b}');
}
Greater Than
void main() {
int a = 10, b = 5;
print('Greater Than: ${a > b}');
}
Less Than
void main() {
int a = 5, b = 10;
print('Less Than: ${a < b}');
}
Greater Than or Equal To
void main() {
int a = 10, b = 10;
print('Greater or Equal: ${a >= b}');
}
Less Than or Equal To
void main() {
int a = 5, b = 10;
print('Less or Equal: ${a <= b}');
}
AND Operator
void main() {
bool a = true, b = false;
print('AND: ${a && b}');
}
OR Operator
void main() {
bool a = true, b = false;
print('OR: ${a || b}');
}
NOT Operator
void main() {
bool a = true;
print('NOT: ${!a}');
}
Bitwise AND
void main() {
int a = 5, b = 3; // 5 = 0101, 3 = 0011
print('Bitwise AND: ${a & b}');
}
Bitwise OR
void main() {
int a = 5, b = 3;
print('Bitwise OR: ${a | b}');
}
Bitwise XOR
void main() {
int a = 5, b = 3;
print('Bitwise XOR: ${a ^ b}');
}
Left Shift
void main() {
int a = 5;
print('Left Shift: ${a << 1}');
}
Right Shift
void main() {
int a = 5;
print('Right Shift: ${a >> 1}');
}
Simple Assignment
void main() {
int a = 10;
print(a);
}
Add and Assign
void main() {
int a = 5;
a += 10;
print(a);
}
Subtract and Assign
void main() {
int a = 20;
a -= 5;
print(a);
}
Multiply and Assign
void main() {
int a = 5;
a *= 4;
print(a);
}
Divide and Assign
void main() {
double a = 10;
a /= 2;
print(a);
}
Modulus and Assign
void main() {
int a = 10;
a %= 3;
print(a);
}
void main() {
int a = 5;
print('Increment: ${++a}');
//Decrement
int b = 5;
print('Decrement: ${--b}');
//Unary Minus
int c = 5;
print('Unary Minus: ${-c}');
}
//is
void main() {
int a = 10;
print(a is int); // true
}
//is!
void main() {
double a = 3.14;
print(a is! int); // true
}
Ternary Conditional
void main() {
int a = 10, b = 20;
String result = (a > b) ? 'a is greater' : 'b is greater';
print(result);
}
Null Coalescing Operator (??)
void main() {
String? name;
print(name ?? 'Default Name');
}
Null-Aware Assignment (??=)
void main() {
String? name;
name ??= 'Default Name';
print(name);
}
Null-Aware Access (?.)
void main() {
String? name;
print(name?.length);
}
Using Cascade
void main() {
List<int> numbers = [];
numbers..add(1)..add(2)..add(3);
print(numbers);
}
Equality
void main() {
int a = 5, b = 5;
print(a == b);
}
Identity (identical)
void main() {
var a = 'hello';
var b = 'hello';
print(identical(a, b)); // true
}
String Concatenation
void main() {
String first = 'Hello', second = 'World';
print(first + ' ' + second);
}
Indexing
void main() {
List<int> numbers = [10, 20, 30];
print(numbers[1]); // 20
}
Spread Operator (...)
void main() {
List<int>? a;
List<int> b = [...?a, 1, 2];
print(b); // [1, 2]
}
Null-Aware Spread (...?)
void main() {
List<int>? a;
List<int> b = [...?a, 1, 2];
print(b); // [1, 2]
}
Range Operator
void main() {
for (int i = 1; i <= 5; i++) {
print(i);
}
}
This covers arithmetic, relational, logical, assignment, unary, bitwise, ternary, null-aware, type-test, and more. Let me know if you'd like detailed explanations or additional examples!