Is it a simple case of just never using the this.XYZ construct?
views:
173answers:
5It's only considered poor style if it violates your style guidelines. Sometimes using this
is necessary to qualify a member variable over a local variable:
public MyType(int arg)
{
this.arg = arg;
}
This problem can also be mitigated with style guidelines. For example, prefix members with "_":
public MyType(int arg)
{
_arg = arg;
}
HTH, Kent
I wouldn't say it's poor style - but it's not particularly idiomatic.
My almost sole use of this.foo
is when copying parameters into fields:
public Person (string name, string occupation)
{
this.name = name;
this.occupation = occupation;
}
I've never heard of it being a style issue. I used to do it all the time to get intellisense, but then I started using ctrl-j, then I just found myself remembering my object's properties without having to use a crutch.
Probably because my objects have become less complex as I gain more experience...
I always use this. for global variable. This way, I can clearly know that I am using a global variable without having to use prefix like "_".
The MS tool StyleCop insists on the this.XYZ (or should that be this.Xyz) variant when analysing source code.