zoukankan      html  css  js  c++  java
  • 索引器

            class myListBox
            {
                    protected ArrayList data = new ArrayList();
                    public object this[int idx]
                    {
                            get
                            {
                                    if(idx > -1 && idx < data.Count)
                                    {
                                            return (data[idx]);
                                    }
                                    else
                                    {
                                            // possibly throw an exception here
                                            return null;
                                    }
                            }
                            set
                            {
                                    if(idx > -1 && idx < data.Count)
                                    {
                                            data[idx] = value;
                                    }
                                    else if (idx == data.Count)
                                    {
                                            data.Add(value);
                                    }
                                    else
                                    {
                                            // possibly throw an exception here
                                    }
                            }
                    }
            }
        class TestApp
            {
                    [STAThread]
                    static void Main(string[] args)
                    {
                            myListBox lBox = new myListBox();
                            lBox[0] = "First";
                            lBox[1] = "Second";
                            lBox[2] = "Third";
                            Console.WriteLine("{0},{1},{2}",lBox[0],lBox[1],lBox[2]);
                    }
            }
  • 相关阅读:
    并发队列 – 无界阻塞队列 LinkedBlockingQueue 原理探究
    并发队列 – 有界阻塞队列 ArrayBlockingQueue 原理探究
    Java回调机制解读
    一张图看懂encodeURI、encodeURIComponent、decodeURI、decodeURIComponent的区别
    uva 111 History Grading
    hdu 2546 饭卡
    hdu 2602 Bone Collector
    uva 10720 Graph Construction
    uva 10716 Evil Straw Warts Live
    uva 10070 Camel trading
  • 原文地址:https://www.cnblogs.com/kevinge/p/1337198.html
Copyright © 2011-2022 走看看