- 1. 字符串类型
- 1.1 字符串拼接
- 2. 集合类型
- 3. Maps(字典)
- 4. 类型判断
void main() { String str = '''this is str this is str this is str this is str'''; print(str); }
void main() { String str = """this is str this is str this is str this is str"""; print(str); }1.1 字符串拼接
void main() { String str1 = 'Hello'; String str2 = 'Dart'; print('$str1 $str2'); }
void main() { String str1 = 'Hello'; String str2 = 'Dart'; print(str1 + str2); }2. 集合类型
void main() { var l1 = ["张三", 20, true]; print(l1); print(l1.length); print(l1[1]); }
// 定义 List,指定类型 void main() { var l2 =["张三", "李四"]; print(l2); }
void main() { var l = []; print(l); print(l.length); l.add("zhangsan"); l.add("李四"); l.add(20); print(l); print(l.length); }
// 创建一个固定长度的集合 void main() { var l = List.filled(2, ""); print(l); l[0] = "张三"; l[1] = "李四"; print(l); }3. Maps(字典)
void main() { var person = { "name": "张三", "age": 20, "work": ["程序员", "外卖员"] }; print(person); print(person["name"]); print(person['work']); }
void main() { var p = new Map(); p["name"] = "李四"; p["age"] = 22; p["work"] = ["程序员", "外卖员"]; print(p); }4. 类型判断
void main() { var str = '1234'; if (str is String) { print('是string类型'); } else if (str is int) { print('是int类型'); } else { print('其他类型'); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)