is there "this"?
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Nov 3 06:40:11 PDT 2016
On 11/2/16 4:43 AM, Jonathan M Davis via Digitalmars-d-learn wrote:
> On Wednesday, November 02, 2016 02:42:01 Konstantin Kutsevalov via
> Digitalmars-d-learn wrote:
>> I tested already and it really works, thank you.
>> I asked that because I tried once to use "this" in past but I got
>> error. So I asked on some forum "how to get property of class?"
>> and peoples said that I may use just a name of property. So I
>> thought that there isn't "this" word.
>
> I don't know why you were having trouble before, but I think that most
> people never use an explicit this unless they need to, so plenty of folks
> would have just told you to remove the this from you code, especially if it
> worked without.
In the case of the original post, however, you *need* to use this.value,
as the parameter masks the member of the same name. Using 'this' removes
ambiguity.
This is a typical pattern seen in many languages. Often the intuitive
name of a member is the same name as you want for the parameter of the
constructor.
-Steve
More information about the Digitalmars-d-learn
mailing list