Naming convention for VB.NET private fields

Question :

Naming convention for VB.NET private fields,

Answer :

Is there an official convention for naming private fields in VB.NET? For example, if I have a property called ‘Foo’, I normally call the private field ‘_Foo’. This seems to be frowned upon in the

“Do not use a prefix for field names. For example, do not use g_ or s_ to distinguish static versus non-static fields.”

In C#, you could call the private field ‘foo’, the property ‘Foo’, and refer to the private field as ‘this.foo’ in the constructor. As VB.NET is case insensitive you can’t do this – any suggestions?

Read More  What is the best way to merge mp3 files?

,

I still use the _ prefix in VB for private fields, so I’ll have _foo as the private field and Foo as the property. I do this for c# as well and pretty much any code I write. Generally I wouldn’t get too caught up in “what is the right way to do it” because there isn’t really a “right” way (altho there are some very bad ways) but rather be concerned with doing it consistently.

At the end of the day, being consistent will make your code much more readable and maintainable than using any set of “right” conventions.

Read More  What is a Covered Index?

That’s the answer Naming convention for VB.NET private fields, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you