- 复合赋值操作符就是使用另一个操作符来组合赋值的句法快捷方式
x = 2 ==> x = x2
x<<=1 ==> x=x<<1 - 事件event是个例外,+=和-=映射到event的add和remove访问器
Null合并操作符
??
string s1 = null;
string s2 = s1 ?? "nothing"; //s2 = "nothing"
string s3 = "something";
string s4 = s3 ?? "nothing"; //s4 = "something"
?.
- 允许像 . 操作符那样调用方法或访问成员,除非当左边的操作数是null的时候,那么整个表达式就是null,而不会抛出NullReferenceException
- 一旦遇到null,这个操作符就把剩余表达式给短路掉了
网友评论