class Statistics
{
Dictionary<decimal, Statistic> BabyDataStandardAgeHeadCircumference;
Dictionary<decimal, Statistic> BabyDataStandardAgeLength;
Dictionary<decimal, Statistic> BabyDataStandardAgeWeight;
Dictionary<decimal, Statistic> BabyDataStandardWeightForLength;
}
These data are fixed – readonly and i want to load them from the database.
The problem is
- How to make them readonly ?(i know
through properties) - How to fill them with data at program startup ?
Calling a method like Statistics.load() from startup event seems poor to me..
Question:
Answer: Rather than using a
Dictionary<decimal, Statistics>, think about using an immutable wrapper for the dictionary.SO link for an implementation of an immutable Dictionary class here:
Does C# have a way of giving me an immutable Dictionary?
Question:
Answer: Rather than fill them with data at program startup, how about filling them at the first access to the class (static or instanced)? This would mean populating these dictionaries in the static constructor (naturally the dictionaries would have to be static members as well).