Maps类的代码

Maps这个类也许是所有读者最关心的问题,也许我的确忘记交代了,可是在5-11图中,读者完全应该能看出该类的原理。为了不让大家继续困扰,特给出代码,更简单:

public class Maps : IMaps, IDisposable
    {
        private IList<IMap> _mapList = null;

        #region class constructor
        public Maps()
        {
            _mapList = new List<IMap>();
        }
        #endregion

        #region IDisposable Members

        /// <summary>
        /// 释放集合对象
        /// </summary>
        public void Dispose()
        {
            if (_mapList != null)
            {
                _mapList.Clear();
                _mapList = null;
            }
        }

        #endregion

        #region IMaps Members

        /// <summary>
        /// 移除指定的地图
        /// </summary>
        /// <param name="Index"></param>
        public void RemoveAt(int Index)
        {
            if (Index > _mapList.Count || Index < 0)
                throw new Exception("Maps::RemoveAt:\r\n索引越界!");

            _mapList.RemoveAt(Index);
        }

        /// <summary>
        /// 清除所有Map
        /// </summary>
        public void Reset()
        {
            _mapList.Clear();
        }

        /// <summary>
        /// 返回Map集合中Map数量
        /// </summary>
        public int Count
        {
            get
            {
                return _mapList.Count;
            }
        }

        /// <summary>
        /// 返回指定的Map对象
        /// </summary>
        /// <param name="Index"></param>
        /// <returns></returns>
        public IMap get_Item(int Index)
        {
            if (Index > _mapList.Count || Index < 0)
                throw new Exception("Maps::get_Item:\r\n索引值越界!");

            return _mapList[Index];
        }

        /// <summary>
        /// 删除一个指定的Map对象
        /// </summary>
        /// <param name="Map"></param>
        public void Remove(IMap Map)
        {
            _mapList.Remove(Map);
        }

        /// <summary>
        /// 产生一个新地图并将其添加到Map集合中
        /// </summary>
        /// <returns></returns>
        public IMap Create()
        {
            IMap newMap = new MapClass();
            _mapList.Add(newMap);

            return newMap;
        }

        /// <summary>
        /// 将一个Map添加到集合中
        /// </summary>
        /// <param name="Map"></param>
        public void Add(IMap Map)
        {
            if (Map == null)
                throw new Exception("Maps::Add:\r\n新地图没有初始化!");

            _mapList.Add(Map);
        }

        #endregion
    }

转载于:https://www.cnblogs.com/chiangbt/archive/2008/12/04/1347324.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值