static void Main(string[] args) { int lowNumber = 0; int highNumber = 0; Divider divider; NObjects nObjects = new NObjects(); lowNumber = CommonUI.GetAPositiveIntegerFromUserInput(AppConsts.numericalInputLowerBound, AppConsts.lowNumerPrompt); highNumber = CommonUI.GetAPositiveIntegerFromUserInput(lowNumber + 1, AppConsts.highNumberPrompt); PopulateNObjects(nObjects); try { Delegates.DisplayDelegate display = Display.DisplayMessageOnConsole; divider = new Divider(lowNumber, highNumber); nObjects.RunDivider(divider, display); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.Write("Hit any key to exit this program..."); Console.ReadKey(); }
/// <summary> /// This function loops through the items of the collection of values and performs the division or attemps to divide. /// The result returned will be displayed by the print delegate, which is set by the caller. /// </summary> /// <param name="divider"></param> /// <param name="print"></param> public void RunDivider(IDivider divider, Delegates.DisplayDelegate display) { string returnResult; display("There are " + _nObjects.Count() + " elements in the collection."); foreach (NObject nObject in _nObjects) { returnResult = divider.Divide(nObject); display(returnResult); } }