美文网首页
c# 表达式和操作符

c# 表达式和操作符

作者: 柒轩轩轩轩 | 来源:发表于2019-07-20 04:42 被阅读0次
    • 复合赋值操作符就是使用另一个操作符来组合赋值的句法快捷方式
      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,这个操作符就把剩余表达式给短路掉了

    相关文章

      网友评论

          本文标题:c# 表达式和操作符

          本文链接:https://www.haomeiwen.com/subject/gwkflctx.html