heres a nice easy one...

  • Thread starter Thread starter Sam Martin
  • Start date Start date
S

Sam Martin

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
 
The Java Guy hidden deep inside me these days is screaming .. "go for the
last one !!!"

Angel
O:]
 
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";
 
Hi Sam,

Sam Martin said:
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
 
Sam Martin said:
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
 
hi jon, couldn't see constants specified. have you got a direct url?

(btw, thanks all for you opinions)
 
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
 
Back
Top