473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1207
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*********@yahoo.co.uk> wrote in message
news:er**************@TK2MSFTNGP12.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*********@yahoo.co.uk> wrote in message
news:er**************@TK2MSFTNGP12.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*********@yahoo.co.uk> wrote in message
news:er**************@TK2MSFTNGP12.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*********@yahoo.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.com>
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*********@yahoo.co.uk> wrote in message
news:er**************@TK2MSFTNGP12.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.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Sam Martin <sa*********@yahoo.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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7
Sam Martin <sa*********@yahoo.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/cpconClassMemberUsageGuidlines.asp

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

--
Jon Skeet - <sk***@pobox.com>
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*********@yahoo.co.uk> wrote in message
news:er**************@TK2MSFTNGP12.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.MaxValue, 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.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
Sam Martin <sa*********@yahoo.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/cpconClassMemberUsageGuidlines.asp

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

--
Jon Skeet - <sk***@pobox.com>
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
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...
6
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...
16
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...
1
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....
2
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...
2
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...
11
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...
3
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...
3
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
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...

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.