CA1500 vs. SA1309 - Which one wins?

后端 未结 6 1196
野性不改
野性不改 2021-01-01 12:36

I\'ll prefix by saying that I understand that both Code Analysis and StyleCop are meant as guidelines, and many people chose to ignore these anyway. But having said that, I

6条回答
  •  天涯浪人
    2021-01-01 12:59

    Simple, use the suffix 'Field' for private fields when there's a class:

     private Int32 counterField;
    
     public Int32 Counter
     {
         get
         {
              return this.counterField;
         }
    
         set
         {
               if (this.counterField != value)
               {
                    this.counterField = value;
                    this.OnPropertyChanged("Counter");
                }
          }
    

    And you can satisfy both rules. Decorating your variables with any characters or hungarian prefixes is tribal. Everybody can find a rule that they don't like in StyleCop or FXCop, but a standard only works when everyone uses it. The benefits of an automated scrubber of code far outweigh your own personal 'artistic' contributions to the language.

提交回复
热议问题