I used this. prefix for approximately two years (StyleCop SA1102 rule). But now I changed my mind and used the underscore prefix for static and private private fields and removed the "this". Console.
Here are my reasons to switch from "this." "emphasize":
- Easy breaks: No one on your team will ever use this. ”Prefix, so when you see a project that follows this style, you will not see“ this. ”Prefix for all members of the instance.
- Useless distinction: . What is the advantage of distinguishing instance fields and statics? Do you ever get any of this?
- Noise: If you take care of using "this." prefix, you will see "this" anywhere. For example, we had 77 times the keyword “this” in the class, but after changing our style, we only have 9 underscores, and I think the code is more readable (you can easily follow the logic of the code).
- Razor . It seems ugly to use "this." prefix in Razor C # codes. For example, you would have "@ this.Html.Something" instead of "@ Html.Something". And we like the general rule to apply to all of our C # codes everywhere.
What is your idea?
Is it possible to ignore the StyleCop SA1102 rule (prefix "this.") And use the underscore prefix to distinguish class fields?
source