tags:

views:

840

answers:

2

I'd like to offer a list of constants within my DLL.

Example usage:

MyDLL.AddHouse( HouseName, MyDll.HOUSETYPES.Big)
MyDLL.AddHouse( HouseName, MyDll.HOUSETYPES.Small)

Tried:

public static readonly string[] HOUSETYPES =
{
  "Big", "Small"
};

But that only gets me:

MyDLL.AddHouse( HouseName, MyDll.HOUSETYPES.ToString())

Any ideas? Thanks.

+4  A: 

Try using an enumeration. In C# this is the best option.

As the enumerations are strongly typed, instead of having an API that takes a string, your api will take a value of the type of your enumeration.

public enum HouseTypes
{
   Big,
   Small
}
MyDll.Function(HouseTypes Option)
{
}

You can then call this code via the enum

{
   MyDll.Function(HouseTypes.Big)
}

FYI as a coding style all caps in C# is reserved for constants only.

Spence
I don't think all caps is recommended even for Constants.
SolutionYogi
+2  A: 
public static class HouseTypes
{
    public const string Big = "Big";
    public const string Small = "Small";
}

It is a good idea to follow .NET naming standards for naming your classes and variables. E.g. class will be called HouseTypes (Pascal Case) and not HOUSETYPES (Upper case).

SolutionYogi