using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WhileSample
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnCalculate_Click(object sender, RoutedEventArgs e)
        {
            //TODO: 1.声明变量
            int total = 0;
            int currentNumber = 1;
            int lastNumber;

            //TODO:2.取出文字输入框中的数字
            lastNumber = int.Parse(txtNumber.Text);

            //TODO:3.建立while循环执行运算
            while (currentNumber <= lastNumber) {
                total += currentNumber;
                currentNumber++;
            }
            //TODO:4.打印结果
            tbResult.Text = String.Format("从1加到{0}的结果是{1}.", lastNumber, total);

        }
    }
}
