CS.ASSIGN.SELF

语言实体已分配给自身。

漏洞与风险

自赋值没有任何作用。即使这不是其自身的错误,它也可能预示代码中将出现更大的错误。

示例 1

复制
  class Foo {
      struct Boo {
          public int x;
          public Boo(int _x) {
              x = _x;
          }
      }
    
      void Assigner() {
         decimal d = 0;
         d = d;             // defect
         Boo boo1 = new Boo(1), 
             boo2 = new Boo(2);
         boo1.x = boo2.x;   // OK
         boo2.x = boo2.x;   // defect
     }
 }