I’m programming using C#, after programming on C. So I’m using a lot of constants such as “DEFAULT_USER_ID”, “REMOTE_ADDRESS” and such…
It seems to me that it’s pretty “old fashioned” to use such constants and maybe there is some other more elegant way for using some constant data between objects.
Any ideas on how this could be done elegantly?
Thanks.
Using constants for stuff like
DEFAULT_USER_IDis still “the way to go” (unless you want it to be configurable, but that’s another topic). –> const (C# Reference)Don’t use constants for enumerations (
FILE_TYPE_DOC = 1,FILE_TYPE_XLS = 2, …). This can be done more elegantly in C# with enums:You can also use this for flags (constants combinable by bitwise operators), which is another common use case of constants in C: