import 'dart:math'; //use math library
//Comment
///Doc comment
/// # header
/// - list
// main - program start point
void main() { //function body
//variable declaration
var z; //dynamic type
z = 1; z = 1.0; z = 'one'; //don’t do that
//all is Object - no primitive types!
Object? v = null; //can be null
//Subclassing from Object -> num -> int or double
//Methods: round, truncate, toInt, toDouble, parse
print('10.isEven: ${10.isEven}'); //print expression
//type inference when assigning value
var w = 1; //int - 1 is integer, 1.0 is double, ...
//Type-safe - static typing
w = 5; //type int can store only integers
//statement with expression x = 5 / 2
// ~/ - truncating division operator
var x = 5 / 2; //decimal number 2.5 by default
print('5 / 2 = $x'); //print variable
//call a function from math library
var y = sin(45 * pi / 180); //min, max, sqrt, sin, cos
//Immutability: Const -> final -> var
const PI = 3.14; //compile time constant
final t = DateTime.now().hour; //runtime constant
//arithmetic operators
var c = 0;
c = c + 1; // +, -, *, /, ~/, %
c += 1; // +=, -=, *=, /=, ~/=, %=
c++; //c++, c--, ++c, --c
print(c);
}
Комментариев нет:
Отправить комментарий