Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 645 Bytes

200602.md

File metadata and controls

61 lines (45 loc) · 645 Bytes

dart 常用数据类型

常量

// 编译时常量,运行之后不能改变
const a = 2;
const a = 5 * 3; // 报错

// 惰性常量,在运行时第一次使用前才初始化
final int a = 5 * 3;

布尔值

bool flag = true;
bool flag1 = false;

数值

// 整数型
int num1 = 1

// 浮点型
double num2 = 2.3

字符串

String str = "hello world";

数组

// Array
List arr = ["aa", 0];
List<int> arr = [1, 0];
List<double> arr = [1.2, 1.3];

// Set
Set<int> set = new Set();

对象

// 弱类型
Map obj = {
  "a": 1
}

// 强类型
Map<String, int> obj1 {
  "a": 1
}