Hi everybody,
I would like to know what is the “right way” to use constants in C#
I need to define relatively large number of constant values that need to be accessible from throughout the application.
Should I just create a class that will have all the definitions as “public const…”, and every class that will need to use this value will just create this object?
Is there any better way to do it? Does C# provide any built-in mechanism to do so?
thanks
bartPosted Jul 31, 2006, 2:41 PM
public class AppConstants
{
}
So in your code this gives you better access:
AppConstants.Reporting.SomeConstA
or
AppConstants.AppInfo.AppTitle
- bart -
Bhakeeswaran ThulasingamPosted Jul 31, 2006, 12:29 PM
Instead of declaring constant variables u can declare them as static readonly variables as below, so that u can access them with ease.
public
class AppConstants{
public static readonly System.String AppName = "My Apps";}