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 专业开发: 气象软件、监狱网上购物系统、两法衔接平台
  • 相关阅读:
    [Python] Python2 、Python3 urllib 模块对应关系
    [Python] Mac pip安装的模块包路径以及常规python路径
    git 使用详解
    版本控制工具简介
    python基础练习题(二)
    python简介,安装
    python基础练习题(一)
    python练习题之面向对象(三)
    python之input函数,if,else条件语句使用的练习题(一)
    C++ 静态变量
  • 原文地址:https://www.cnblogs.com/sucsy/p/3099252.html
Copyright © 2011-2022 走看看