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]);
                    }
            }
  • 相关阅读:
    [05] EL表达式
    [03-01] JSP自定义标签
    [04] JSP标准动作
    [03] JSP指令
    Fiddler抓包调试前端脚本代码
    《互联网协议入门》思维导图笔记
    Nodejs学习笔记(十)—与MongoDB的交互(mongodb/node-mongodb-native)、MongoDB入门
    Nodejs学习笔记(九)—与Redis的交互(mranney/node_redis)入门
    Nodejs学习笔记(八)—Node.js + Express 实现上传文件功能(felixge/node-formidable)
    Nodejs学习笔记(七)—Node.js + Express 构建网站简单示例
  • 原文地址:https://www.cnblogs.com/kevinge/p/1337198.html
Copyright © 2011-2022 走看看