Silverlight 下创建Hashtable

Silverlight 下创建Hashtable,第1张

概述using System;using System.Collections;using System.Collections.Generic;using System.Linq;namespace SFire.Framework{ /// <summary> /// Silverlight下使用的哈希表 /// 创建者:sucsy /// 创建日期:20
using System;using System.Collections;using System.Collections.Generic;using System.linq;namespace SFire.Framework{    /// <summary>    /// Silverlight下使用的哈希表    /// 创建者:sucsy    /// 创建日期:2012-2-27    /// </summary>    public class DataHashtable : IDictionary    {        List<HashtableItem> table = null;        public DataHashtable()        {            this.table = new List<HashtableItem>();        }        public voID Add(object key,object value)        {            if (this.Contains(key) == false)            {                table.Add                    (                        new HashtableItem()                        {                            Key = key,Value = value                        }                    );            }            else            {                this[key] = value;            }        }        public voID Clear()        {            table.Clear();        }        public bool Contains(object key)        {            foreach (HashtableItem item in this.table)            {                if (item.Key!=null && item.Key.Equals(key)) return true;            }            return false;        }        public IDictionaryEnumerator GetEnumerator()        {            return (IDictionaryEnumerator)this.table.ToArray().GetEnumerator();        }        public bool IsFixedSize        {            get { return false; }        }        public bool IsReadonly        {            get { return false; }        }        public ICollection Keys        {            get { return this.table.Select(item => item.Key).ToArray(); }        }        public voID Remove(object key)        {            HashtableItem item = Find(key);            if (item != null) this.table.Remove(item);        }        private HashtableItem Find(object key)        {            HashtableItem find = null;            foreach (HashtableItem item in this.table)            {                if (item.Key.Equals(key))                {                    find = item;                    break;                }            }            return find;        }        public ICollection Values        {            get { return this.table.Select(item => item.Value).ToArray(); }        }        public object this[object key]        {            get            {                HashtableItem item = Find(key);                if (item != null) return item.Value;                return null;            }            set            {                HashtableItem item = Find(key);                if (item != null) item.Value = value;            }        }        public voID copyTo(Array array,int index)        {            this.table.copyTo((HashtableItem[])array,index);        }        public int Count        {            get { return this.table.Count; }        }        public bool IsSynchronized        {            get { return true; }        }        public object SyncRoot        {            get { return null; }        }        IEnumerator IEnumerable.GetEnumerator()        {            return this.table.GetEnumerator();        }    }    #region 哈希表项    /// <summary>    /// 哈希表项    /// </summary>    public class HashtableItem    {        /// <summary>        /// 关键字        /// </summary>        public object Key { get; set; }        /// <summary>        /// 源对象        /// </summary>        public object Value { get; set; }    }    #endregion}


南京酷得软件

总结

以上是内存溢出为你收集整理的Silverlight 下创建Hashtable全部内容,希望文章能够帮你解决Silverlight 下创建Hashtable所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1019108.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存