-
变量:查看全部
-
?? 什么鬼
## ??= 短路赋值运算符, TS ?
```dart
void main() {
dynamic d;
print("d = ${d}");
// null || 1;
// ??= 短路赋值运算符, TS ?
d ??= 1;
print("d ??= ${d}");
// var n = null;
// "" ❌不好使
// var n = "";
// n ??= "string";
// print("n ??= ${n}");
// 0 ❌不好使
// var n = 0;
// n ??= 7;
// print("n ??= ${n}");
// false ❌不好使
// var n = false;
// n ??= true;
// print("n ??= ${n}");
print("\n");
int i = 0;
print("i = ${i}");
i += 3;
print("i += ${i}");
i -= 1;
print("i -= ${i}");
i *= 3;
print("i *= ${i}");
// int ❌, /= 必须是 double 类型,
// i /= 2;
// print("i /= ${i}");
i %= 2;
print("i %= ${i}");
// double, ✅ /= 必须是 double 类型
double dd = 2.0;
dd /= 2;
print("dd /= ${dd}");
// int => double, ✅ / 必须是 double 类型
int x = 3;
// x = x / 2;
print("x / 2 = ${x / 2}");
}
```
查看全部 -
??= 什么鬼
## ??= 短路赋值运算符, TS ?
```dart
void main() {
dynamic d;
print("d = ${d}");
// null || 1;
// ??= 短路赋值运算符, TS ?
d ??= 1;
print("d ??= ${d}");
// var n = null;
// "" ❌不好使
// var n = "";
// n ??= "string";
// print("n ??= ${n}");
// 0 ❌不好使
// var n = 0;
// n ??= 7;
// print("n ??= ${n}");
// false ❌不好使
// var n = false;
// n ??= true;
// print("n ??= ${n}");
print("\n");
int i = 0;
print("i = ${i}");
i += 3;
print("i += ${i}");
i -= 1;
print("i -= ${i}");
i *= 3;
print("i *= ${i}");
// int ❌, /= 必须是 double 类型,
// i /= 2;
// print("i /= ${i}");
i %= 2;
print("i %= ${i}");
// double, ✅ /= 必须是 double 类型
double dd = 2.0;
dd /= 2;
print("dd /= ${dd}");
// int => double, ✅ / 必须是 double 类型
int x = 3;
// x = x / 2;
print("x / 2 = ${x / 2}");
}
```
查看全部 -
math operator
查看全部 -
list.asMap
查看全部 -
keys, values
```dart
print("map.keys = ${map.keys}");
print("map.values = ${map.values}");
print("map.entries = ${map.entries}");
```
查看全部 -
[], length
isEmpty, isNotEmpty
Keys, Values, Entries
containsKey(), containsVlaue()
remove()
forEach()
查看全部 -
```dart
void main() {
dynamic map = {"a": 1, "b": 2, "c": 3, "str": "string", "bool": true};
print("map = $map");
const mc = {"key": 1, "str": "string", "bool": true};
print("mc = $mc");
// var m = new Map("key", 1);
// var m = new Map({"key": 1});
var m = new Map();
// m.addEntries({"key": 3});
// m.addEntries();
m.addAll({"key": 3});
print("m = $m");
}
```
查看全部 -
```dart
/*
void forEach(void f(E element)) {
for (E element in this) f(element);
}
*/
```
查看全部 -
forEach() 不是 List 专有的,只是一个通用迭代器方法
```dart
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2019-01-01
*
* @description
* @augments
* @example
*
*/
void main() {
dynamic list = [1, 2, 3, "string", false];
print("list = $list");
list.forEach(print);
print("\n");
list.forEach((key, i) => {
print("list = $key, $i")
// print("list = $key");
// Error: Expected '}' before this.
});
}
// forEach() 不是 List 专有的,只是一个通用迭代器方法
/*
list = [1, 2, 3, string, false]
list = 1
list = 2
list = 3
list = string
list = false
*/
```
查看全部 -
[], length
add(), insert()
remove(), clear()
indexOf(), lastIndexOf()
sort(), sublist()
shuffle(), asMap(), forEach()
查看全部 -
list === array
查看全部 -
```dart
void main() {
String s = "string";
print("s = $s");
String replaceAll = "string string".replaceAll("s", "S");
print("replaceAll = $replaceAll");
String replaceFirst = "string string".replaceFirst("s", "s");
print("replaceFirst = $replaceFirst");
String replaceFirstMapped = "string string".replaceFirstMapped("s", (match) => null);
print("replaceFirstMapped = $replaceFirstMapped");
String replaceAllMapped = "string string".replaceAllMapped("s", (match) => null);
print("replaceAllMapped = $replaceAllMapped");
String replaceRange = "string string".replaceRange(0, 1, "S");
print("rreplaceRange = $replaceRange");
}
```
查看全部 -
方法
contains(), substring()
startsWith(), endsWith()
indexOf(), lastIndexOf()
toLowerCase(), toUpperCase()
trim(), trimLeft(), trimRight()
split(), replace???()
查看全部 -
属性 length, isEmpty, isNotEmpty
查看全部
举报