c# style for private variable using _ or this? -


i know prefer way refer private field in c# code?

is using underscore in front of variable _ or using this prefer way?

what benefits , disadvantages of these 2 styles?

in code

private string _name;  private void getname() {      return string.format("{0} - hello", _name); } 

or second method

private string name;  private void getname() {      return string.format("{0} - hello", this.name); } 

i prefer 2nd method, because clearer me variable name belong instance, , used them extensively in javascript, dont see them used in c#, first style prefer

there isn't rule or general recommendation this. should pick 1 way , stick it, or agree on 1 if in team.

the advantage of using underscore on this it's part of variable name. can access _name _name, not name. when use this can access name instead of this.name.

javascript conventions doesn't translate c# private members, there no private members in javascript, , there no class scope way access member using this.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -