-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path操作符.dart
53 lines (46 loc) · 959 Bytes
/
操作符.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Dart对象操作符
// ?条件运算符
// as类型转换
// is类型判断
// ..级联操作
class Person{
String name;
num age;
Person(this.name,this.age);
void printInfo(){
print("${this.name}-${this.age}");
}
}
class Person1{
String name;
int age;
printInfo(){
print("${this.name}-${this.age}");
}
}
main(){
// Person p;
// p.printInfo(); //对象为空的时候会报错
// Person p;
// p?.printInfo();//对象为空时不会报错
// print("123");
// Person p = new Person("张三",20);
// if(p is Person){
// p.name="李四";
// }
// p.printInfo();
// print(p is Object);
// var p1;
// p1='';
// p1=new Person("张三",20);
// // (p1 as Person).printInfo();
// p1.printInfo();
Person1 person = new Person1();
person .. name = "王五"
..age = 18
..printInfo();
// 也可以使用这种匿名对象的方式
new Person1()..name = "李四"
..age = 18
..printInfo();
}