﻿using System;
using System.Collections;
namespace ClassLib.IndexOperator
{
    public class People
    {
        //public string Name { get; set; }
        //public int Age { set; get; }
        public ArrayList Group = new ArrayList();
        public string this[int i]
        {
            get
            {
                if (i > -1 && i < Group.Count)
                {
                    return Group[i].ToString();
                }
                return "this is out of index";

            }
            set
            {
                try
                {
                    Group.Add(value);
                    Group[i] = value;
                }
                catch (IndexOutOfRangeException ex)
                {
                    throw ex;
                }
            }
        }
    }
    public class IndexOperator
    {
        public People a;
        public IndexOperator()
        {
            a = new People();
            a.Group.Add("Jack");
        }
        public void TestCase()
        {
            Console.WriteLine(a[0]);
            a[100] = "Ken";
            //Console.WriteLine(a[100]);
        }
    }
}
