标题:程序代码中 pos和data这个两个索引器各自起到了什么作用 解释下 谢谢
取消只看楼主
狂牛
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-11-5
 问题点数:0 回复次数:0 
程序代码中 pos和data这个两个索引器各自起到了什么作用 解释下 谢谢
class OvrIndexer
    {
        private string[] myData;
        private int arrSize;
        public OvrIndexer(int size)
        {
            arrSize = size;
            myData = new string[size];
            for (int i = 0; i < size; i++)
            {
                myData[i] = "empty";
            }
        }

        public string this[int pos]
        {
            get
            {
                return myData[pos];
            }
            set
            {
                myData[pos] = value;
            }
        }

        public string this[string data]
        {
            get
            {
                int count = 0;
                for (int i = 0; i < arrSize; i++)
                {
                    if (myData[i] == data)
                    {
                        count++;
                    }
                }
                return count.ToString();
            }
            set
            {
                for (int i = 0; i < arrSize; i++)
                {
                    if (myData[i] == data)
                    {
                        myData[i] = value;
                    }
                }
            }
        }
搜索更多相关主题的帖子: private public return 
2011-11-05 11:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-354347-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049049 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved