How to handle multiple global constants in an application<!-- --> | <!-- -->Patrick Desjardins Blog
Patrick Desjardins Blog
Patrick Desjardins picture from a conference

How to handle multiple global constants in an application

Posted on: October 22, 2012

The best way to have something organized and having constants in a single place is to have a class that will have inner class. This way, you can organize by theme your constants.

1public static class GlobalConstants {
2 public static class Division1 {
3 public const string Const1 = "123";
4 public const string Const2 = "qwe";
5 public const string Const3 = "asdfgh";
6 }
8 public static class Division2 {
9 public const string Const1 = "123";
10 }

Of course, it's always better to have your constant in the class that they are more related. For example, the default value for a specific property of a class should be directly inside this class. But, for global constants that are used across the application, than having a global constants class can do the job.