I am working on a windows service C# project and I am working first time in C#.
An I am getting 2 different suggestion from VS as well Stylecop for a same this
keyword. (I know, this
keyword refers to the current instance of the class)
So I removed this keyword, and I am getting stylecop suggestion as
SA1101 : CSharp.Readability : The call to serializeBackupFilePath must begin with the 'this.' prefix to indicate that the item is a member of the class.
So, I am confused here, so is there will have any difference between constructor having this
keyword and constructor without this
keyword
(Sorry for my bad english)
I prefer not using
this
. However, since you are using the same naming convention for arguments and class members, it might be hard to differentiate between those two without it.Since you are using C# I'd recommend this naming convention to avoid cases where you need to use
this
to explicitly specify which one you mean:_name
for private class membersName
for public class members, constants and method namesname
for arguments and local variablesStyleCop's official description for
SA1101
is:I disagree completely with that, but maybe it helps you decide wether to use
this
or not.Btw: this has already been discussed StyleCop's Github.
The official recommendation is to disable
SA1101
.