// On new instance, this will fired, which will setup the dictionary protected void Initiate(int numberOfMultipliers) { // Ensure you have an active instance of the dictionary if (Multipliers == null) { Multipliers = new Dictionary <string, float>(); } // Ensurance if (numberOfMultipliers > 0) { MultCount = numberOfMultipliers; for (int x = 1; x <= numberOfMultipliers; x++) { if (!Multipliers.ContainsKey("Mult" + x)) { Multipliers.Add("Mult" + x, 0); } } } else { throw new ArgumentOutOfRangeException(); } }
// This is the main method to generate the multiplication part. public void Generate(int multNumber, int multiplier) { if (multNumber == 0) { Multipliers["Mult"] = Source * multiplier; } else if (Multipliers.ContainsKey("Mult" + multNumber)) { // store the value in the dictionary (this is for reference) Multipliers["Mult" + multNumber] = SetMult(multNumber, Source * multiplier); } else { throw new NullReferenceException(); } }