Silverlight 下创建Hashtable
using System; System.Collections; System.Collections.Generic; 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>(); } void Add(object key,object value) { if (this.Contains(key) == false) { table.Add ( new HashTableItem() { Key = key,Value = value } ); } else { this[key] = value; } } void Clear() { table.Clear(); } bool Contains( key) { foreach (HashTableItem item in this.table) { if (item.Key!=null && item.Key.Equals(key)) return true; } ; } IDictionaryEnumerator GetEnumerator() { return (IDictionaryEnumerator).table.ToArray().GetEnumerator(); } bool IsFixedSize { get { ; } } IsReadOnly { ICollection Keys { this.table.Select(item => item.Key).ToArray(); } } void Remove( key) { HashTableItem item = Find(key); if (item != null) .table.Remove(item); } private HashTableItem Find( key) { HashTableItem find = ; if (item.Key.Equals(key)) { find = item; break; } } return find; } ICollection Values { item.Value).ToArray(); } } object this[ key] { get { HashTableItem item = Find(key); item.Value; ; } setnull) item.Value =void copyTo(Array array,255)">int index) { .table.copyTo((HashTableItem[])array,index); } Count { .table.Count; } } IsSynchronized { SyncRoot { ; } } IEnumerator IEnumerable.GetEnumerator() { .table.GetEnumerator(); } } #region 哈希表项 哈希表项 HashTableItem { <summary> 关键字 </summary> object Key { get; ; } 源对象 object Value { ; } } #endregion }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。