Given the fact that current C # 3.0 allows for automatic properties, the syntax of which is similar:
public int Property {get; set;}
the extra work required to use properties on public fields is almost zero. The fact is that you can never be completely sure that the field will not be used in another way or that the accessor will never change, and given the compromise in the work, there is no reason not to implement the property.
In any case, the analyzer complains about things that, in a high percentage (in this case, for example, 99.99% of cases), are bad programming practice ... but in any case, it just complains. Fields can be made public, and there are some extreme cases where its direct use may be warranted. Like never before, use your common sense ... but keep in mind the elemental rule for best programming practices ... Is there really good reason to break the agreement? If there then go ahead, if not, or if the answer is "it takes more work," then stick to the practice ...
Jorge Cรณrdoba Jan 26 '09 at 17:45 2009-01-26 17:45
source share