示例#1
0
        /// <summary>
        /// Handler for operations with two arguments
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void CalculateTwoArguments(object sender, EventArgs e)
        {
            try
            {
                string InputOne = ValueOneInput.Text;
                string InputTwo = ValueTwoInput.Text;

                if (InputOne.Length == 0 || InputTwo.Length == 0)
                {
                    throw new Exception("Argument missing");
                }

                string senderName    = ((Button)sender).Name;
                string operationName = senderName.Replace("Button", "");

                double firstValue  = MyValidator.ValidateAndConvertToDouble(ValueOneInput.Text);
                double secondValue = MyValidator.ValidateAndConvertToDouble(ValueTwoInput.Text);

                ITwoArgumentsCalculator Calculator = TwoArgumentsFactory.CreateCalculator(operationName);
                var calculateResult = Calculator.Calculate(firstValue, secondValue);

                OutputField.Text = calculateResult.ToString();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "Error");
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="toSplit"></param>
        /// <param name="delimiter"></param>
        /// <returns></returns>
        public static double[] StringToArray(string toSplit, char delimiter)
        {
            if (toSplit.Length == 0)
            {
                throw new Exception("Sent an empty string");
            }

            string[] stringItems = toSplit.Split(delimiter);
            double[] result      = new double[stringItems.Length];

            for (int i = 0; i < stringItems.Length; i++)
            {
                var item = stringItems[i];

                if (item.Length == 0)
                {
                    throw new Exception("Sent an crushed string");
                }

                result[i] = MyValidator.ValidateAndConvertToDouble(item);
            }
            return(result);
        }