How to declare a static dictionary object inside a static class? I tried
public static class ErrorCode
{
public const IDictionary E
Old question, but I found this useful. Turns out, there's also a specialized class for a Dictionary using a string for both the key and the value:
private static readonly StringDictionary SegmentSyntaxErrorCodes = new StringDictionary
{
{ "1", "Unrecognized segment ID" },
{ "2", "Unexpected segment" }
};
Edit: Per Chris's comment below, using Dictionary over StringDictionary is generally preferred but will depend on your situation. If you're dealing with an older code base, you might be limited to the StringDictionary. Also, note that the following line:
myDict["foo"]
will return null if myDict is a StringDictionary, but an exception will be thrown in case of Dictionary. See the SO post he mentioned for more information, which is the source of this edit.