日期:2014-05-18 浏览次数:20989 次
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            MyCls myCls = new MyCls();
            Console.WriteLine(myCls["c"]);
            Console.ReadKey();
        }
    }
    class MyCls
    {
        public MyCls()
        { }
        public string this[string itemName]
        {
            get 
            {
                switch (itemName)
                {
                    case "a": return "Hi, A.";
                    case "b": return "Hi, B.";
                    default: throw new Exception("unknown item name.");
                }
            }
        }
    }
}