第一个疑惑的问题是关于IIS服务器的会话的,一台服务器的IIS 6.0昨天访问,发现会话在20秒左右就会丢失,而这个程序没有修改,也没有修改什么配置,检查一天无果。
最后发现服务器时间是2005年1月1日,少了近30天,修改后一切正常,不是吧!怎么这样 有哪位高人解释一下原理。

今天写程序,写到这里
不是吧!怎么这样            if ( serviceProviders.Contains(serviceProvider) )
不是吧!怎么这样                serviceProviders.Remove(serviceProvider);
感觉有些浪费,俩次查找定位,这让我突然有兴趣看看范型实现的内部代码(我的这个集合使用的List<>)
不是吧!怎么这样        private List<IServiceProvider> serviceProviders = new List<IServiceProvider>();
不是吧!怎么这样

使用Reflector反编译工具查看其实现
不是吧!怎么这样public bool Contains(T item)
{
不是吧!怎么这样      
if (item == null)
{
不是吧!怎么这样            
for (int num1 = 0; num1 < this._size; num1++)
{
不是吧!怎么这样                  
if (this._items[num1] == null)
{
不是吧!怎么这样                        
return true;
不是吧!怎么这样                  }

不是吧!怎么这样            }

不是吧!怎么这样            
return false;
不是吧!怎么这样      }

不是吧!怎么这样      IComparer
<T> comparer1 = Comparer<T>.Default;
不是吧!怎么这样      
for (int num2 = 0; num2 < this._size; num2++)
{
不是吧!怎么这样            
if (comparer1.Equals(item, this._items[num2]))
{
不是吧!怎么这样                  
return true;
不是吧!怎么这样            }

不是吧!怎么这样      }

不是吧!怎么这样      
return false;
不是吧!怎么这样}

不是吧!怎么这样 
不是吧!怎么这样

我倒不是吧!怎么这样 这个效率 …… 怎么说你也用个 Hash冒个泡吧。
后来,看了一下IndexOf,是调用数组的,但一看数组,也是一样的实现。

经过非常“深刻”的思考,哦,是自己使用不当,如果想通过 key 查找,用 System.Collections.Generic.Dictionary<K,V>最好,看看实现吧
private int FindEntry(K key)
{
      if (key == null)
      {
            ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
      }
      if (this.buckets != null)
      {
            int num1 = this.comparer.GetHashCode(key) & 0x7fffffff;
            for (int num2 = this.buckets[num1 % this.buckets.Length]; num2 >= 0; num2 = this.entries[num2].next)
            {
                  if ((this.entries[num2].hashCode == num1) && this.comparer.Equals(key, this.entries[num2].key))
                  {
                        return num2;
                  }
            }
      }
      return -1;
}

相关文章: