这真的是一种简化吗? [英] Is this really a simplification?
问题描述
所以我有一个带有 Id
字段的非常简单的类,并且 Id
可以在构造函数中设置.
So I have a pretty simple class with an Id
field, and the Id
can be set in the constructor.
通常我会使用 this
来清楚地标识类属性而不是方法参数.对我来说,这似乎更清楚.
Typically I will use this
to clearly identify the class property as opposed to the method argument. To me this seems clearer.
IDE0003 要我删除this
,并显示名称可以简化",对吗?
IDE0003 wants me to remove the this
, with the message 'Name can be simplified', is that correct?
这对我来说似乎不太清楚,而且还允许大小写错误很容易导致 id = id
.
This seems less clear to me, and also allows a casing error to easily result in id = id
.
推荐答案
this
关键字几乎总是不必要的,参见 你什么时候使用this"?关键字?.
The this
keyword almost always is unnecessary, see When do you use the "this" keyword?.
允许大小写错误很容易导致 id = id
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?
这篇关于这真的是一种简化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!