• 索引器


            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]);
                    }
            }
  • 相关阅读:
    乐观锁悲观锁及其使用场景
    inner join, left join, right join的作用是什么
    主键和唯一索引的区别
    在排序数组中查找元素的第一个和最后一个位置
    寻找旋转排序数组中的最小值
    [模板] 最小费用最大流
    CF878E Numbers on the blackboard
    CF1286F Harry The Potter
    CF1368H1 Breadboard Capacity
    CF1442E Black, White and Grey Tree
  • 原文地址:https://www.cnblogs.com/kevinge/p/1337198.html
Copyright © 2020-2023  润新知