zoukankan      html  css  js  c++  java
  • Silverlight 下创建Hashtable 南京酷得软件

    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
    }


    南京酷得软件

    公司网站: http://www.codersoft.cn 专业开发: 气象软件、监狱网上购物系统、两法衔接平台
  • 相关阅读:
    求幂运算、多项式乘法及Horner法则的应用
    JAVA泛型中的类型擦除及为什么不支持泛型数组
    关于递归的理解及递归表达式复杂度分析(以求解最大公约数为例)
    随机序列生成算法---生成前N个整数的一组随机序列
    Windows 与 Linux下关于端口不能访问的问题
    Netty 实现HTTP文件服务器
    字符数组转换成数字
    字符串反转的进一步应用----单词反转
    递归算法编程整数因子分解问题的递归算法
    数据返回[数据库基础]——图解JOIN
  • 原文地址:https://www.cnblogs.com/sucsy/p/3099252.html
Copyright © 2011-2022 走看看