-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.dart
45 lines (37 loc) · 1.04 KB
/
variables.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Variables in Dart
* - Variables are used to store data in a program
* - Variables declaration
*/
void main() {
// without type-checking
var firstName = "Muzakkir Hossain";
dynamic age = 10;
print(firstName);
print(age);
// with type-checking
String lastName = "Minhaz"; // string
double temparature = 27.8; // double
int number = 10; // int
bool isRain = false; // bool
String? fullName;
print(fullName);
print(lastName);
print(temparature);
print(number);
print(isRain);
print(firstName + " " + lastName); // string concatenation
// immutable variable
const name = "Muzakkir Minhaz";
final int salary = 1000;
// name = "Muzakkir"; // error : cannot re-assign to 'name'
// number = 20; // error : cannot re-assign to 'number'
print(name);
print(salary);
// type conversion / casting
double salaryDouble = 1000;
int salaryInt = salaryDouble.toInt(); // convert double to int
print(salaryInt);
String salaryString = salaryDouble.toString(); // convert double to string
print(salaryString);
}