索引器

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]);
            }

 

posted @ 2020-11-21 12:03  boenotuch  阅读(90)  评论(0)    收藏  举报