Posted 30 September 2012 - 08:25 PM
I can see those not many replies happen in this place so here is a stone I'm dropping into a deep dark well as many others already have.
I understand the concept of sending it to an instance in order to reference to the sending instance. That makes perfect sense. But I constantly see "this" used inside of a class to reference a variable that is already inside the class.
If a class has a global variable called "variable1" then why does it need to be referenced as this.variable1 from inside the class? It's not so much that I can't see why it would be done but I can't see why it would be done one time and not the next. For instance in the bee solution on page 260 I see:
this.shiftsToWork = numberOfShifts;
and right under it I see
shiftsWorked = 0;
both of these variables are global to the class, bother are private, both are int. There is nothing different about either variable. ANd yet one is referenced by this and the other is not.
If it doesn't need to be done then why the heck is it being thrown in there? Just to be confusing? To make us think? Because it's really distracting and in fact I've spent the last hour of my life trying to find the answer to this instead of learning the part of the book I'm on.
The book does not provide a good answer to this (at least not so far), microsoft help just says "this is used in order to qualify a field". Why does it need to be qualified? We know it's there or it wouldn't work. If I decide NOT to use this it's still going to pull the information from the field it was called from.