Is this really a simplification?
The this
keyword almost always is unnecessary, see When do you use the "this" keyword?.
allows a casing error to easily result in
id = id
That will yield another warning on its own:
Assignment made to same variable; did you mean to assign something else?
If you want to prevent the warning in code rather then updating Visual Studio settings, use the SuppressMessage
data annotation, which will prevent the warning.
It looks something like this:
[SuppressMessage("Reason #Enter whatever you'd like", "ID, must match what intellsense is showing it looks something like this: IDE0001", Justification = "(optional, your own description")]
Here is an exact example for your "this" variable situation:
[SuppressMessage("IntelliSenseCorrection", "IDE0003", Justification = "Allowing usage of 'this' keyword to maintain consistency/readability of code.")]
This other question has an answer that says you can configure the editor to remove the behavior. Personally I like "this"
Tools > Options > Text Editor > C# > Code Style and check Qualify member access with 'this'
Visual Studio 2015 - Change Light Bulb, Quick Action settings
If you use General Naming Conventions
then the this
keyword is redundant because the parameter should be id
and the property should be Id
based on Naming Guidelines
. So it seems clear:
public int Id
{
get;
private set;
}
public VSOMessage(int id)
{
Id = id;
}
Please note that the guidelines itself don't say, to use or not use this
keyword but because C# is case sensitive, it would be a simplification to remove this
keyword but when you don't use Naming Conventions then you may naming the property id
instead ofId
so you should use this
keyword in such cases.