1

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.

1
  • Any reason not to use an enum? Commented Jul 4, 2009 at 15:52

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't think all caps is recommended even for Constants.
Correct - the guidelines from Microsoft say that all capitals should never be used in C#. social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/…
4
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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.