B
Brett Romero
I'd like to know when exactly the this. keyword is needed. For
example:
public class Combination
{
private long n = 0;
private long k = 0;
private long[] data = null;
public Combination(long n, long k)
{
if (n < 0 || k < 0) // normally n >= k
throw new Exception("Negative parameter in constructor");
this.n = n;
this.k = k;
this.data = new long[k];
for (long i = 0; i < k; ++i)
this.data = i;
}
}
In the above code, I can see how this. may differentiate my class
scoped vars vs. parameters. If the class vars would have been nn and
kk instead of n and k, would this. still have been needed?
I've always viewed this. as useful for intelliparse but ultimately just
additional parsing. So I remove it.
Thanks,
Brett
example:
public class Combination
{
private long n = 0;
private long k = 0;
private long[] data = null;
public Combination(long n, long k)
{
if (n < 0 || k < 0) // normally n >= k
throw new Exception("Negative parameter in constructor");
this.n = n;
this.k = k;
this.data = new long[k];
for (long i = 0; i < k; ++i)
this.data = i;
}
}
In the above code, I can see how this. may differentiate my class
scoped vars vs. parameters. If the class vars would have been nn and
kk instead of n and k, would this. still have been needed?
I've always viewed this. as useful for intelliparse but ultimately just
additional parsing. So I remove it.
Thanks,
Brett