我遇到了C#multithreaded dictionary concurrentdictionary的一个奇怪问题。无论是TryGetValue
还是ContainsKey
,它始终返回false。有谁知道发生了什么事?
这是我的测试代码:
public static ConcurrentDictionary<byte[], int> OnlineDic;
static void Main(string[] args)
{
OnlineDic = new ConcurrentDictionary<byte[], int>();
OnlineDic.TryAdd(Encoding.UTF8.GetBytes("99"),99);
bool b = OnlineDic.TryGetValue(Encoding.UTF8.GetBytes("99"),out int i);
Console.WriteLine(b);
Console.WriteLine(OnlineDic.ContainsKey(Encoding.UTF8.GetBytes("99")));
Console.ReadKey();
}