Does Microsoft have any naming guidelines for variables? I've been
reading their guidelines for just about every other type (methods,
parameters, properties, etc.) but nothing about variables. Are variables
treated the same as parameters (i.e., camel case)?
I notice that Hungarian notation is being done away with.
Also, is it good practice to use an underscore to begin the name of a
field? I've seen that, and it seems like a good idea, but I didn't know
if that wasn't part of the suggested guidelines either.
Thanks,
John 3 2370
Microsoft has only provided naming guidelines for your public API -
which would be your public classes, interfaces, methods, etc. Local
variables, private fields, and even private methods and classes can be
named however you want. The naming guidelines are not to make your
internal source code more readable, they are intended to make your
consumer's source code more readable, by making your API consistent with
other .NET components.
There is no Microsoft recommended guideline (that I have seen) regarding
private variables or fields. Some people like an underscore prefix,
some like "m_", some just prefer using the same name as the public
property, just camelCased, instead of PascalCased (and prefixed with
"this." to avoid conflict with a similarly named method parameter).
Bottom line is that the decision is up to you. Decide on a standard
that you and your team are comfortable with and stick to it.
John Salerno wrote: Does Microsoft have any naming guidelines for variables? I've been reading their guidelines for just about every other type (methods, parameters, properties, etc.) but nothing about variables. Are variables treated the same as parameters (i.e., camel case)?
I notice that Hungarian notation is being done away with.
Also, is it good practice to use an underscore to begin the name of a field? I've seen that, and it seems like a good idea, but I didn't know if that wasn't part of the suggested guidelines either.
Thanks, John
John Salerno wrote: Also, is it good practice to use an underscore to begin the name of a field? I've seen that, and it seems like a good idea, but I didn't know if that wasn't part of the suggested guidelines either.
It's not necessarily good or bad. If it helps you, it's fine.
As a former C++ programmer, it bothers me, as a user-defined name
beginning with an underscore would be illegal according to the C++ Standard,
but there's no reason why that should hold sway in C# code.
--
Truth,
James Curran [erstwhile-MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: boxboy |
last post by:
I am hoping someone from Microsoft could shed some insight into this
question.
Why did microsoft decide to use a verb based naming convtion for events
rather such as Close and Click for rather than prepending them with On as in
OnClose and OnClick?
The way it is now, I encounter a lot of naming conflicts/ambiguity when
trying to follow Microsoft's reccommened approach in naming my own events.
|
by: Ted |
last post by:
I'm trying to come up with naming conventions for my
company as we move to C#. I'm looking through the Naming
Guidelines section on MSDN, but I'm unable to find a
recommendation for class scope variables.
Working with WinForms, I believe it would be helpful to
have some type of prefix. In Visual Basic we used
m_variableName. But I can't find any suggestions on this.
Any help on this would be great. Thanks,
|
by: Sandeep Sharma |
last post by:
For many years I have been following the convention of naming all
class attributes with a leading underscore. This enables me to
quickly identify the class attributes when I encounter them in the
source code. Even the GoF book follows this convention, although it's
true that the GoF book is not an authoritative source for coding
guidelines.
Recently a colleague remarked that using a leading underscore is a bad
programming practice...
|
by: Robert Jacobson |
last post by:
Hello all,
If I have a class called "Foo," is there a preferred naming convention for
iterating through each Foo instance in a collection of Foos? I've seen
several different variations, even in the MSDN documentation:
#1:
For each Foo as Foo in Foos
...
|
by: Jonathan Wood |
last post by:
I was just wondering what naming convention most of you use for class
variables.
Underscore, "m_" prefix, camel case, capitalized, etc?
Has one style emerged as the most popular?
Thanks for any comments.
--
| |
by: Smithers |
last post by:
Is it common practise to begin the name of form classes with "frm" (e.g.,
frmOneForm, frmAnotherForm).
Or is that generally considered an outdated convention?
If not "frm" what is a common or recommended practise?
Thanks.
|
by: mrashidsaleem |
last post by:
Can anyone guide me what is wrong with the naming conventions
suggested below? I know that this is not recommended by many
(including Microsoft) but I need to know what exactly is the rationale
behind going for a different convention in .NET. The recommendations
do make sense (to me, at least but I may be wrong and would like
someone to correct me).
Scope Prefixes
Member Variable Prefix: Most of the people still use (and like the
idea...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |