Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the more elegant way to declare a const in C# [duplicate]

Possible Duplicate:
C# naming convention for constants?

I'm refactoring a library in C# and I found a lot of upper case constants:

INTERVAL, TIME, SECONDS.

I think this a kind of unnecessary, and personally I prefer declare everything with camel case. Exist some exactly definition about the better way?

like image 667
Custodio Avatar asked Nov 30 '22 10:11

Custodio


2 Answers

Ultimately the case isn't going to make any difference (unless it collides with a type/keyword/etc). So really consistency is the main thing.

The Capitalization Conventions don't distinguish between constants and other members - but these are guidelines only. So it would be pascal-case.

like image 194
Marc Gravell Avatar answered Dec 05 '22 06:12

Marc Gravell


All-caps constants are a common convention…

…but a convention is just that, and is arbitrary. If you are writing code for yourself, there is no compelling reason not to choose your own. If you work with other developers, you must all agree on a naming convention.

If you are writing something that will be consumed by others outside your team, you might do well to stick to the most common and recognizable naming conventions to avoid confusion.

In the end, consistency is what counts.

like image 41
Jay Avatar answered Dec 05 '22 08:12

Jay