Last active
January 22, 2020 15:00
-
-
Save AlexVegner/945eef1999697bde6f7e73072bbe2d65 to your computer and use it in GitHub Desktop.
dart_built_in_types.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// dynamic can take any type | |
dynamic dy1 = 'Text'; | |
dy1 = 2; | |
// String type | |
String s1 = 'Hello'; | |
String s2 = "World"; | |
String s3 = ''' | |
Multi-line | |
string | |
'''; | |
String s4 = 'String concatenation ' + s1 + s2; | |
String s5 = 'String interpolation $s1 ${'My' + s2}'; | |
// runes (for expressing Unicode characters in a string) | |
var clapping = '\u{1f44f}'; | |
// Boolean | |
bool b = true; | |
b = false; | |
b = null; | |
bool b2; // variable of any without initialization will be null | |
// int // double | |
var i = 1; // int decimal based on 10, 64 bits or 32 bits (for JS) | |
int hex = 0xDEADBEEF; // int | |
double d = 1.2; // floating-point numbers, 64 bits or 32 bits (for JS) | |
var d1 = 1.42e5; // exponents format | |
// int and double are subtypes of num | |
String binary = '10100'; // binary base-2 | |
int decFromBinaryValue = int.parse(binary, radix: 2); | |
String oct = '10'; // octal base-8 | |
int decFromOctValue = int.parse(oct, radix: 8); | |
String hexStr = '10'; // hexadecimal base-16 | |
int decFromHexValue = int.parse(hexStr, radix: 16); | |
int decvalue = 20; // | |
print('dec $decvalue = hex ${decvalue.toRadixString(16)} = oct ${decvalue.toRadixString(8)} = bin ${decvalue.toRadixString(2)}'); | |
// symbols - Used very rarely, for example in reflection | |
Symbol obj = new Symbol('name'); | |
obj = #name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment