Using HashTable to realize a set which Provide a collection that contains a group of unique objects

it2022-05-09  29

Set  1using System; 2using System.Collections; 3namespace Utilities 4{ 5    /**//// <summary> 6    /// Provide a collection that contains a group of unique 7    /// objects. 8    /// </summary> 9    public class Set10    {11        private Hashtable h = new Hashtable();12        /**//// <summary>13        /// Return an enumerator for this set.14        /// </summary>15        /// <returns>An enumerator for this set</returns>16        public IEnumerator GetEnumerator()17        {18            return h.Keys.GetEnumerator();19        }20        /**//// <summary>21        /// Add the provided object to this set.22        /// </summary>23        /// <param name="o">the object to add</param>24        public void Add(Object o)25        {26            h[o] = null;27        }28        /**//// <summary>29        /// Return true if the set contains the presented object.30        /// </summary>31        /// <param name="o">the object of curiosity</param>32        /// <returns>true, if the set contains the presented object</returns>33        public bool Contains(Object o)34        {35            return h.Contains(o);36        }37    }38}

转载于:https://www.cnblogs.com/nanshouyong326/archive/2007/05/09/740016.html

相关资源:数据结构—成绩单生成器

最新回复(0)