1 回答

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊
使用ConcurrentDictionarycan 解決您遇到的問題。在這里,我假設(shè)您的屬性是雙精度類型TimeStamp,但它可以是任何類型,只要您使ConcurrentDictionary鍵與類型匹配即可。
class Program
{
ConcurrentDictionary<double, Store> _StoreQueue = new ConcurrentDictionary<double, Store>();
static void Main(string[] args)
{
var T = 17d;
// try to add if not exit the store with 17
_StoreQueue.GetOrAdd(T, new Store(T));
}
public class Store
{
public double TimeStamp { get; set; }
public Store(double timeStamp)
{
TimeStamp = timeStamp;
}
}
}
- 1 回答
- 0 關(guān)注
- 308 瀏覽
添加回答
舉報(bào)