VisualStudio建议在重要地方删除this-Keyword?

VisualStudio suggests deleting this-Keyword in important place?

正如标题所说,VisualStudio 17 (15.7.1) 建议删除一个 "unnecessary" 这在我看来实际上很重要。

假设我们有以下简约 Class:

class ThisExampleClass
{
    public int ThisTest1 { get; set; }
    public int ThisTest2 { get; set; }

    public ThisExampleClass()
    { }

    public ThisExampleClass(int ThisTest1, int ThisTest2)
    {
        this.ThisTest1 = ThisTest1;
        this.ThisTest2 = ThisTest2;
    }
}

到目前为止一切顺利。但是如果我写下面几行代码,VisualStudio 17建议删除this-Keywords.

class ThisExampleShowcase
{
    private int ThisTest1;
    private int ThisTest2;

    public ThisExampleShowcase()
    { }

    public void ShowQuestion()
    {
        ThisTest1 = 10;
        ThisTest2 = 11;
        var ThisTest = new ThisExampleClass()
        {
            ThisTest1 = this.ThisTest1, // delete this.
            ThisTest2 = this.ThisTest2  // delete this.
          //ThisTest2 = ThisTest2          Suggested but seems wrong
        };
    }
}

编译器会知道分配哪个 ThisTest 吗? 据我所知,这可能会影响变量,但即使您删除了 "this." ,一切似乎都没有问题。

在这种情况下,C# 和 .NET 是否会自动假定右侧变量的 "this." 含义?

Would the compiler know which ThisTest to assign?

是的。在这种情况下,您不能在赋值中使用新创建对象的属性,因此只有一个 ThisTest.

Does C# and .NET automatically assume a "this." meaning for the right hand side variables in this case?

没有。这种情况是特殊情况,因为左侧是 属性 赋值。在常规作业中,它可能会模棱两可。