Esempio n. 1
0
        public static Result TryParse(string line)
        {
            var result = new Result();
            var f      = new MyInt();

            try
            {
                f.value     = int.Parse(line);
                result.Data = f;
            }
            catch (Exception ex)
            {
                result.IsSuccessful = false;
                result.Errors.Add(new Error()
                {
                    Code = 1, Message = ex.Message
                });
            }

            return(result);
        }
Esempio n. 2
0
        private void btn2_Click(object sender, RoutedEventArgs e)
        {
            String line = txt2.Text;

            string[] temp = line.Split(new string[] { "+" },
                                       StringSplitOptions.RemoveEmptyEntries);

            int len = temp.Length;

            MyInt[] array      = new MyInt[len];
            int     checkError = 0;

            for (int i = 0; i < len; i++)
            {
                var result = MyInt.TryParse(temp[i]);
                if (result.IsSuccessful)
                {
                    var f = result.Data as MyInt;
                    array[i] = f;
                }
                else
                {
                    checkError = 1;
                    StringBuilder sError = new StringBuilder();
                    foreach (var error in result.Errors)
                    {
                        string s2 = error.Code + " " + error.Message + "\n";
                        sError.Append(s2);
                    }
                    MessageBox.Show("Co loi khi khoi tao : " + sError.ToString());
                    break;
                }
            }
            if (checkError == 0)
            {
                MyInt sum = new MyInt();
                sum.Tong1(array);
                txt2.Text = sum.value + "";
            }
        }