Using nested classes for constants?

Posted by antirysm on Stack Overflow See other posts from Stack Overflow or by antirysm
Published on 2010-05-31T19:17:52Z Indexed on 2010/05/31 19:23 UTC
Read the original article Hit count: 191

Filed under:
|
|

What's wrong with using nested classes to group constants?

Like so:

public static class Constants
{
    public static class CategoryA
    {
        public const string ValueX = "CatA_X";
        public const string ValueY = "CatA_Y";
    }
    public static class CategoryB
    {
        public const string ValueX = "CatB_X";
        public const string ValueY = "CatB_Y";
    }
}

Used like so:

Console.WriteLine(Constants.CategoryA.ValueY);
Console.WriteLine(Constants.CategoryB.ValueX);

You could also make the "Constants"-class partial...

© Stack Overflow or respective owner

Related posts about c#

Related posts about constants