Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

const naming convention

0 views
Skip to first unread message

Jens Gruschel

unread,
Mar 27, 2002, 11:11:22 AM3/27/02
to
Hello,

Might be a stupid one: Is there any naming convention for constants in C#?
Should I write

const int ERROR_OUTOFMEMORY = 2

or

const int errorOutOfMemory = 2

or is it just a case of personal matter?

Jens

-glenn-

unread,
Mar 27, 2002, 12:46:33 PM3/27/02
to
Jens, seems to me it is a matter of personal style. I prefer to use all
upper-case with underscores (like your first example) - I guess it's just a
holdover of using this style for 25-years, starting back in the days when I
cranked out a whole lot of C code.

If you like the style of your second example, use that.

As always, be sure to be consistent in whatever style you adopt - that's the
main thing!

-glenn-

"Jens Gruschel" <grus...@esteam.de> wrote in message
news:Ol1Wqma1BHA.2588@tkmsftngp07...

Jens Gruschel

unread,
Mar 27, 2002, 1:17:09 PM3/27/02
to
> Jens, seems to me it is a matter of personal style. I prefer to use all
> upper-case with underscores (like your first example) - I guess it's just
a
> holdover of using this style for 25-years, starting back in the days when
I
> cranked out a whole lot of C code.

That's the point. Upper-case looks like C / C++, I've not seen it in C# yet
(could be because I just started with C#). Good luck such integer constants
are not used often (I just made a class which does not use such constants
out of the code that was the reason for my question).

Jens

Chris Osborn

unread,
Mar 27, 2002, 1:22:04 PM3/27/02
to
I am transitioning from using your first example (upper case) to using enums
instead. I feel they provide better encapsulation of like constants which
in-turn makes it easier for other developers to understand. Also methods
that return these codes can then return the enumeration type which again
makes things a little cleaner and more OO.


public enum errorCodes
{
OutOfMemory = 2,
InvalidArgument = 3
}

public errorCodes MyMethod()
{
return errorCodes.OutOfMemory;
}


Hope this helps
Chris


"Jens Gruschel" <grus...@esteam.de> wrote in message
news:Ol1Wqma1BHA.2588@tkmsftngp07...

Kevin McFarlane

unread,
Mar 27, 2002, 3:39:46 PM3/27/02
to
Hi Jens,

Try looking at the Microsoft .Net Design Guidelines.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/ht
ml/cpconnetframeworkdesignguidelines.asp

You're not obliged to follow them of course. But I suggest not straying too
far from them.

Kevin


"Jens Gruschel" <grus...@esteam.de> wrote in message
news:Ol1Wqma1BHA.2588@tkmsftngp07...

Eric Janson

unread,
Mar 28, 2002, 8:10:30 AM3/28/02
to
Perhaps picayune minutia, but a singular variable name for an enum seems
more appropriate. When it's used, which is much more often than it's
declared, it's more intuitive to see a singular, like

errorCode.OutOfMemory

"Chris Osborn" <cos...@usdata.com> wrote in message > public enum

0 new messages