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]);
                    }
            }
  • 相关阅读:
    python中的深拷贝和浅拷贝
    Andrew NG 机器学习编程作业6 Octave
    Andrew NG 机器学习编程作业5 Octave
    梯度下降算法对比(批量下降/随机下降/mini-batch)
    无监督算法
    深度学习的方差与偏差
    Andrew NG 机器学习编程作业4 Octave
    数据约束
    数据库的查询
    MySQL的入门与使用,sqlyog对数据库,表和数据的管理
  • 原文地址:https://www.cnblogs.com/kevinge/p/1337198.html
Copyright © 2011-2022 走看看