索引器

public class ItcastClass
    {
        private string[] _names = { "111", "222", "333", "444", "5555" };
        public int Count
        {
            get { return _names.Length; }
        }
        public string this[int index]
        {
            get { return _names[index]; }
            set { _names[index] = value; }
        }
    }

  

 ItcastClass ic = new ItcastClass();
            Console.WriteLine(ic.Count);
            for (int i = 0; i < ic.Count; i++) {
                Console.WriteLine(ic[i]);
            }
原文地址:https://www.cnblogs.com/boentouch/p/14015175.html