c# 4.0 - Do we need this keyword in .net 4.0 or 4.5 -


i reviewing code written in c#, visual studio 2012.

in lot of places, code written using key word, ex:

this.pnlphonebasicdtls.visible = true; this.setphaggstats(ostats); 

there many other places controls of page referred using key word.

can advise need use here? consequences of removing keyword?

thanks in advance..

the this keyword usually optional.

it's used disambiguate fields arguments if same name being used both, example:

void main() {     var sc = new someclass();     sc.somemethod(123);     console.writeline(sc.thing); }  public class someclass {     public int thing;      public void somemethod(int thing)     {         this.thing = thing + 1;     } } 

in example above make difference. inside somemethod, this.thing refers field , thing refers argument.

(note simpler assignment thing = thing picked compiler error, since no-op.)

of course, if use resharper unnecessary this. (together unused using statements, unreachable code, etc.) greyed out , can remove them quickly. same true of similar tools coderush.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -