473,661 Members | 2,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

heres a nice easy one...

naming conventions for C# constants?

we're having a mild dispute as to what is better and what is more commonly
used?

(better = easy to see as constant, nice to look at in code and most
consistant with what everyone else is doing)

should it be
private const string InternalCode = "ABC";

or

private const string _internal_code = "ABC";

or

private const string INTERNAL_CODE = "ABC";

all ideas welcome

Sam Martin
Nov 16 '05 #1
9 1232
For constants which are also reached from outside the class(public, internal
and/or protected)
i prefer:
public const string InternalCode = "ABC";

For private constants i use:
private const string _INTERNAL_CODE = "ABC";

For local constants i use:
const string INTERNAL_CODE = "ABC";
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Sam Martin" <sa*********@ya hoo.co.uk> wrote in message
news:er******** ******@TK2MSFTN GP12.phx.gbl...
naming conventions for C# constants?

we're having a mild dispute as to what is better and what is more commonly
used?

(better = easy to see as constant, nice to look at in code and most
consistant with what everyone else is doing)

should it be
private const string InternalCode = "ABC";

or

private const string _internal_code = "ABC";

or

private const string INTERNAL_CODE = "ABC";

all ideas welcome

Sam Martin

Nov 16 '05 #2
Hi Sam,

"Sam Martin" <sa*********@ya hoo.co.uk> wrote in message
news:er******** ******@TK2MSFTN GP12.phx.gbl...
naming conventions for C# constants?

we're having a mild dispute as to what is better and what is more commonly
used?

(better = easy to see as constant, nice to look at in code and most
consistant with what everyone else is doing)

should it be
private const string InternalCode = "ABC";

or

private const string _internal_code = "ABC";

or

private const string INTERNAL_CODE = "ABC";

all ideas welcome

Sam Martin


My favored coding standard is to prefix private member variables with an
underscore. It also seems that the traditional standard for constants is ALL
CAPS, terms seperated by underscores. Combining the two you would have:

private const _INTERNAL_CODE = "ABC";

Just my $0.02, of course.

Regards,
Daniel
Nov 16 '05 #3
The Java Guy hidden deep inside me these days is screaming .. "go for the
last one !!!"

Angel
O:]
"Sam Martin" <sa*********@ya hoo.co.uk> wrote in message
news:er******** ******@TK2MSFTN GP12.phx.gbl...
naming conventions for C# constants?

we're having a mild dispute as to what is better and what is more commonly
used?

(better = easy to see as constant, nice to look at in code and most
consistant with what everyone else is doing)

should it be
private const string InternalCode = "ABC";

or

private const string _internal_code = "ABC";

or

private const string INTERNAL_CODE = "ABC";

all ideas welcome

Sam Martin

Nov 16 '05 #4
Sam Martin <sa*********@ya hoo.co.uk> wrote:
naming conventions for C# constants?

we're having a mild dispute as to what is better and what is more commonly
used?

(better = easy to see as constant, nice to look at in code and most
consistant with what everyone else is doing)

should it be
private const string InternalCode = "ABC";

or

private const string _internal_code = "ABC";

or

private const string INTERNAL_CODE = "ABC";


The first, IMO. It makes it consistent with the public constants naming
convention specified at http://tinyurl.com/2cun

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Sam,
Specific answer -
http://msdn.microsoft.com/library/de...guidelines.asp
General Guideliens -
http://msdn.microsoft.com/library/de...guidelines.asp

Jason Newell, MCAD
Software Engineer
"Sam Martin" <sa*********@ya hoo.co.uk> wrote in message
news:er******** ******@TK2MSFTN GP12.phx.gbl...
naming conventions for C# constants?

we're having a mild dispute as to what is better and what is more commonly
used?

(better = easy to see as constant, nice to look at in code and most
consistant with what everyone else is doing)

should it be
private const string InternalCode = "ABC";

or

private const string _internal_code = "ABC";

or

private const string INTERNAL_CODE = "ABC";

all ideas welcome

Sam Martin

Nov 16 '05 #6
hi jon, couldn't see constants specified. have you got a direct url?

(btw, thanks all for you opinions)

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Sam Martin <sa*********@ya hoo.co.uk> wrote:
naming conventions for C# constants?

we're having a mild dispute as to what is better and what is more
commonly
used?

(better = easy to see as constant, nice to look at in code and most
consistant with what everyone else is doing)

should it be
private const string InternalCode = "ABC";

or

private const string _internal_code = "ABC";

or

private const string INTERNAL_CODE = "ABC";


The first, IMO. It makes it consistent with the public constants naming
convention specified at http://tinyurl.com/2cun

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7
Sam Martin <sa*********@ya hoo.co.uk> wrote:
hi jon, couldn't see constants specified. have you got a direct url?


Constants are readonly static fields, so I use the static field
guidelines.

See

http://msdn.microsoft.com/library/de...l=/library/en-
us/cpgenref/html/cpconClassMembe rUsageGuidlines .asp

Also note constants in the framework, such as Int32.MaxValue.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
ThanksAll.
:o)

"Sam Martin" <sa*********@ya hoo.co.uk> wrote in message
news:er******** ******@TK2MSFTN GP12.phx.gbl...
naming conventions for C# constants?

we're having a mild dispute as to what is better and what is more commonly
used?

(better = easy to see as constant, nice to look at in code and most
consistant with what everyone else is doing)

should it be
private const string InternalCode = "ABC";

or

private const string _internal_code = "ABC";

or

private const string INTERNAL_CODE = "ABC";

all ideas welcome

Sam Martin

Nov 16 '05 #9
Hmm..I have to admit that I like the allcaps one better (though it goes
against the .NET standard). Seeing it in capital letters acts as a big red
sign saying it is a constant. If I see something like Integer.MaxValu e, I
think to myself 'Ah..property' - and properties always conjure up images of
things that can change

--
Sriram Krishnan

http://www.dotnetjunkies.com/weblog/sriram
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** @msnews.microso ft.com...
Sam Martin <sa*********@ya hoo.co.uk> wrote:
hi jon, couldn't see constants specified. have you got a direct url?


Constants are readonly static fields, so I use the static field
guidelines.

See

http://msdn.microsoft.com/library/de...l=/library/en-
us/cpgenref/html/cpconClassMembe rUsageGuidlines .asp

Also note constants in the framework, such as Int32.MaxValue.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
2495
by: Dan Perl | last post by:
Here is a python feature that I would like: to be able to import modules from an archive like the jar files in Java. Maybe a regular tar file? Maybe a python specific file type, let's call it a 'par' file? It would be useful in packaging an python library. Sure, there's always the python packages, but a single file instead of a whole directory tree would be more convenient. I am particularly interested because I am working on a...
6
4704
by: Dave Smithz | last post by:
Hi there, A client of mine wants to start generating some reports from their PHP / MYSQL database. They were previously gathering data from the screen and cutting and pasting it into a Word document template. They now just want to generate it. My initial thoughts are to just format the information in a table and then they print it out. But due to the dynamic nature of the reports and what is
16
1576
by: hoggmeister | last post by:
Hi, Im new to C coming from a java background. I having difficulty adjusting to C and was hoping someone could help me with a little simple code to get started. I would like a little program that outputs on to the console a message like "please enter some text" then when the user enters text it gets stored in a char array or whatever is best. I then want to check that the array is no longer than 25 chars ( i dont know if malloc is...
1
3136
by: Maurice Mertens | last post by:
Hi, just started with designing a neat GUI for my Windows Forms. I thought this would be relatively simple but it isn't. I was wondering what you all are using to create a nice looking GUI. Does anyone have some URLs available where I can find some information about this topic? I would appreciate an inspiring screenshot as an attachment of your
2
1175
by: Claudio Grondi | last post by:
Today I bumped by chance into explaining what algorithms do by using animation (Java applets): http://www-sr.informatik.uni-tuebingen.de/~buehler/BM/BM1.html Is there any tool in Python (except pyGame, Tkinter or other general purpose visualization tools) I am not aware of which would make it easy to create a similar, animated run through Python script code? A free debugging tool capable of stepping line by line through Python code...
2
1287
by: avlee | last post by:
Hello Do you know any easy to use php library which could be used for drawing many types of nice looking charts ? (i know i could use gd directly, but maybe there's no need to invent wheel again) Thanx
11
1264
by: darrel | last post by:
I played with ASP.net 2.0 last year a bit but got sidtracked and haven't had a chance to dive into it again until recently. I'm now planning on fully going over to 2.0 and VS.2005 Pretty much every tutorial for 2.0 used SQL Express. I really like it. It's slick, integrated well with VS and it's nice to have it 'contained' within my app. Plus, it makes it really easy to work offline without having to pay for a full SQL license. The one...
3
3865
by: WebCM | last post by:
How to apply nice URL-s into CMS? 1. Should we use nice urls for every page? 2. Do we need to put a FULL path into <a href="">? 3. What is faster and better? a) 10 rules in .htaccess which redirect you to normal URLs with GET parameters
3
2346
sweetzhay
by: sweetzhay | last post by:
i already know how to get the output of 1 12 123 1234 12345 using while wend and now my problem is to show the output of 1 21
0
8341
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,...
0
8851
Oralloy
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...
0
8754
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
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...
0
4177
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...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.