I know this might be a stupid question, but here it goes.
I always wrote my private members like privateMember
and I've been reading a lot about naming conventions in C# because I noticed that a lot of the automatic generated code in visual studio use _variableName
for private members. Everywhere I read, even in Microsoft documents, that you should use privateMember
.
So, my question is, if the good practices says that I should write privateMember
, as I do now, Why the heck Visual Studio generates classes with private members using underscore (_privateMember
)?
Not so long time ago when C# was raising to the market there was a concept that local variables should be leaded by a prefix _
. This concept was not accepted by the community as in pure C the _
leads system variable/functions and the metadata are lead by __
. So after few years, they now discourage to use that. But still you will find some believer that use this notation not because it is a fanatic but a lot of old C# applications contain this convention.
Why this is in VisualStudio ?
This might be related to the time gap it was designed. In those time this approach was suggested by language designers. So it is probably that no one changed that in the configuration for latest version.