1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace IntelligentControlForsx.Code
- {
- public class UpdMemory<T>
- {
- private readonly static ConcurrentDictionary<string, T> _dic=new ConcurrentDictionary<string, T>();
- #region IDictionary<string,ResultType> 成员
- public void Add(string key, T value)
- {
- _dic.TryAdd(key, value);
- }
- public bool ContainsKey(string key)
- {
- return _dic.ContainsKey(key);
- }
- public void AddorUpdate(string key, T value)
- {
- if (ContainsKey(key))
- {
- this[key] = value;
- }
- else
- {
- _dic.TryAdd(key, value);
- }
- }
- public ICollection<string> Keys
- {
- get { return _dic.Keys; }
- }
- public bool Remove(string key)
- {
- T val;
- return _dic.TryRemove(key, out val);
- }
- public bool TryGetValue(string key, out T value)
- {
- return _dic.TryGetValue(key, out value);
- }
- public ICollection<T> Values
- {
- get { return _dic.Values; }
- }
- public T this[string key]
- {
- get
- {
- return _dic[key];
- }
- set
- {
- _dic[key] = value;
- }
- }
- #endregion
- }
- }
|