Say I have a giant list of definitions that are used to lookup values that an object can default to given a "type number". This type number is unique, and points to data that the object will be set to when initialized with it.
My usual go-to is to have a static property that will return a new Dictionary with each get. E.g.
public static Dictionary<long, Tuple<string,DefaultValue>> Defaults
{
get { return new Dictionary<long, DefaultValue>()
{
{ 123, new DefaultValue("Name of default 1", 12312, 23544, ...)},
{ 456, new DefaultValue("Name of default 2", 36734, 74367, ...)},
...
}
}
}
This works, and the lookup list will likely never be large enough for this to noticeably impact performance or memory usage, but being somewhat stingy on performance I don't like the idea of having a new Dictionary
instantiated every time it is referenced. I would much rather it be completely hard-coded into memory.
How would this be solved in a professional way? I feel like the way I am doing it above is incredibly sloppy.