using System;
using System.Collections;
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 ArrayListSample
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        ArrayList memberList = new ArrayList();

        private void DisplayList(string title, ICollection myCollection)
        {
            tbMessage.Text = title + "\n";
            foreach (object obj in myCollection)
            {
                tbMessage.Text += obj.ToString() + "\n";
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            memberList.Add(183);
            memberList.Add("CoCo");
            memberList.Add(DateTime.Now);

            DisplayList("输出memberList:", memberList);
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            Student john = new Student();
            john.ID = "1";
            john.Name = "张书源";

            memberList.Insert(1, john);
            DisplayList("输出memberList:", memberList);
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            memberList.Remove("CoCo");
            DisplayList("输出memberList:", memberList);
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            if (memberList.Contains("CoCo"))
            {
                memberList.Remove("CoCo");
                DisplayList("输出memberList:", memberList);
            }
            else
            {
                DisplayList("CoCo不存在.输出memberList: ", memberList);
            }
        }

        private void button5_Click(object sender, RoutedEventArgs e)
        {
            memberList = new ArrayList(10);

            memberList.Add(183);
            memberList.Add("CoCo");
            memberList.Add(DateTime.Now);

            tbMessage.Text = "ArrayList的容量:" + memberList.Capacity + "\n";
            tbMessage.Text += "ArrayList目前元素的数目:" + memberList.Count + "\n";
            memberList.TrimToSize();
            tbMessage.Text += "运行TrimToSize方法...\n";
            tbMessage.Text += "ArrayList的容量:" + memberList.Capacity + "\n";
        }
    }
}
