This is my second article about getting started
Dart data type
Graph LR A(data type)--> B(String type) A--> C(numeric type) A--> D(Boolean type) A--> E(List) A--> F(Map) A--> G(dynamic)
The data type | Statement of the sample |
---|---|
Type String | String a= “Hello “; Var a =” Hello” |
Numeric types | Double c = 3.14; Var c = 3.14; |
The Boolean bool | bool d = true; |
List the List | var e = [“1″,”2″,”3”]; |
The key value of the Map | Ar person = {“name” :”张三”, “age”: 50}; var f = new Map(); |
Special dynamic | a = ‘Dart’; b = “JavaScript”; |
Type String
In DART, both strings and characters are strings, not char. Declaration, plain declaration, multi-line character declaration, raw string declaration
// Common declaration
String str1 = 'Hello'; // Double quotation marks can also be ""// multi-line string, using three single quotation marks
String str2 = '''Hello Dart''';
// There are escape characters
String str3 = 'Hello \n Dard';
// Raw string, unescaped, preceded by r
str3 = r'Hello \n Dard';
Copy the code
Numeric types
int a = 123;
double b = 22.1; // Can be an integer or a floating-point type
Copy the code
The Boolean
Boolean, true or false.
// Boolean values, only true and false
bool isTrue = true;
bool isFalse = false;print('Hello'.isNotEmpty);
Copy the code
List the List
A list container for storing data. There is no array type.
var list1 = [1.2.3.4.'Dart'.true];// Declare the list
// The new keyword can also be used
list1 = new List(a);Copy the code
The key value of the Map
Map key-value pair type, development is also very common
Mapvar map1 = {'first': 'dart'.1: true.true: 2};// Declare and assign
map1 = new Map(a);// Can also be declared with the new keyword
Copy the code
Special dynamic
Finally, we have our dynamic type, which can be assigned by any type. This is essentially the Java equivalent of Object. Dart is dynamic.
var a;
a = 10; //var This can be assigned to any type
a = 'Dart';
b = "JavaScript"; // Dynamic b = 20;
Copy the code