一切福田,不離方寸,從心而覓,感無不通。

ConcurrentDictionary

表示可由多个线程同时访问的键/值对的线程安全集合。 命名空间:   System.Collections.Concurrent 程序集:  mscorlib(位于 mscorlib.dll) 继承层次结构 System.Object System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> 语法 C#

类型参数 TKey 字典中的键的类型。 TValue 字典中的值的类型。 构造函数 名称 说明 ConcurrentDictionary<TKey, TValue>() 初始化 ConcurrentDictionary<TKey, TValue> 类的新实例,该实例为空,具有默认的并发级别和默认的初始容量,并为键类型使用默认比较器。 ConcurrentDictionary<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>>) 初始化 ConcurrentDictionary<TKey, TValue> 类的新实例,该实例包含从指定的 IEnumerable<T> 中复制的元素,具有默认的并发级别和默认的初始容量,并为键类型使用默认比较器。 ConcurrentDictionary<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>>, IEqualityComparer<TKey>) 初始化 ConcurrentDictionary<TKey, TValue> 类的新实例,该实例包含从指定的 IEnumerable 中复制的元素,具有默认的并发级别和默认的初始容量,并使用指定的 IEqualityComparer<T>。 ConcurrentDictionary<TKey, TValue>(IEqualityComparer<TKey>) 初始化 ConcurrentDictionary<TKey, TValue> 类的新实例,该实例为空,具有默认的并发级别和容量,并使用指定的System.Collections.Generic.IEqualityComparer<T>。 ConcurrentDictionary<TKey, TValue>(Int32, IEnumerable<KeyValuePair<TKey, TValue>>, IEqualityComparer<TKey>) 初始化 ConcurrentDictionary<TKey, TValue> 类的新实例,该实例包含从指定的 IEnumerable 中复制的元素并使用指定的System.Collections.Generic.IEqualityComparer<T>。 ConcurrentDictionary<TKey, TValue>(Int32, Int32) 初始化 ConcurrentDictionary<TKey, TValue> 类的新实例,该实例为空,具有指定的并发级别和容量,并为键类型使用默认比较器。 ConcurrentDictionary<TKey, TValue>(Int32, Int32, IEqualityComparer<TKey>) 初始化 System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> 类的新实例,该实例为空,具有指定的并发级别和指定的初始容量,并使用指定的 System.Collections.Generic.IEqualityComparer<T>。 属性 名称 说明 Count 获取包含在 System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> 中的键/值对的数目。 IsEmpty 获取一个值,该值指示 System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> 是否为空。 Item[TKey] 获取或设置与指定的键关联的值。 Keys 获得一个包含 System.Collections.Generic.Dictionary<TKey, TValue> 中的键的集合。 Values 获取包含 System.Collections.Generic.Dictionary<TKey, TValue> 中的值的集合。 方法 名称 说明 AddOrUpdate(TKey, TValue, Func<TKey, TValue, TValue>) 如果该键不存在,则将键/值对添加到 ConcurrentDictionary<TKey, TValue> 中;如果该键已经存在,则通过使用指定的函数更新 ConcurrentDictionary<TKey, TValue> 中的键/值对。 AddOrUpdate(TKey, Func<TKey, TValue>, Func<TKey, TValue, TValue>) 如果该键不存在,则使用指定函数将键/值对添加到 ConcurrentDictionary<TKey, TValue>;如果该键已存在,则使用该函数更新 ConcurrentDictionary<TKey, TValue>中的键/值对。 Clear() 将所有键和值从 ConcurrentDictionary<TKey, TValue> 中移除。 ContainsKey(TKey) 确定是否 ConcurrentDictionary<TKey, TValue> 包含指定键。 Equals(Object) 确定指定的对象是否等于当前对象。(继承自 Object。) Finalize() 在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。(继承自 Object。) GetEnumerator() 返回循环访问 ConcurrentDictionary<TKey, TValue> 的枚举数。 GetHashCode() 作为默认哈希函数。(继承自 Object。) GetOrAdd(TKey, TValue) 如果该键不存在,则将键/值对添加到 ConcurrentDictionary<TKey, TValue> 中。 GetOrAdd(TKey, Func<TKey, TValue>) 如果该键不存在,则通过使用指定的函数将键/值对添加到 ConcurrentDictionary<TKey, TValue> 中。 GetType() 获取当前实例的 Type。(继承自 Object。) MemberwiseClone() 创建当前 Object 的浅表副本。(继承自 Object。) ToArray() 将 System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> 中存储的键和值对复制到新数组中。 ToString() 返回表示当前对象的字符串。(继承自 Object。) TryAdd(TKey, TValue) 尝试将指定的键和值添加到 System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> 中。 TryGetValue(TKey, TValue) 尝试从 System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> 获取与指定的键关联的值。 TryRemove(TKey, TValue) 尝试从 System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> 中移除并返回具有指定键的值。 TryUpdate(TKey, TValue, TValue) 将指定键的现有值与指定值进行比较,如果相等,则用第三个值更新该键。   示例 C#

[…]

龙生   03 Jul 2018
View Details

SignalR 跨域解决方案全面

SignalR 分:PersistentConnection和Hub 2种模式。 跨域又分:UseCors和JsonP  2种方法 所以例子写了4种。 核心代码: UseCors

Use JsonP

Cross  HUb 前端

Cross Connection 前端

JsonP  HUb

JsonP  connection

代码下载:http://download.csdn.net/detail/shikyoh/9734460 from: https://www.cnblogs.com/shikyoh/p/6272679.html

龙生   03 Jul 2018
View Details