Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why C# and C++ use _<variableName> coding convention?

I have seen too much C# and C++ code where the variable naming convention seems to ask programmers to write variable names using underscore before the text of the variable. e.gr.

int? _countMoney;

What's the rationale supporting that convention?

like image 700
JPCF Avatar asked Sep 29 '10 16:09

JPCF


2 Answers

In C# I usually prefix with _ private fields but never local variables. The rationale behind this is that when I need a private variable I type _ and the Intellisense filters the list and it is easier to find. This way I am also able to distinguish between private from local variables and I no longer need to type this.variablename for class fields but simply _variablename.

like image 68
Darin Dimitrov Avatar answered Oct 18 '22 18:10

Darin Dimitrov


It's just an easy way to identify private member variables.

like image 28
fehays Avatar answered Oct 18 '22 18:10

fehays