c# – 无法将.Net ConcurrentDictionary转换为IReadOnlyDictionary接口?

我必须遗漏一些东西,觉得我必须回到基础,但是.Net 4.5中的ConcurrentDictionary according to the reference sources它实现了IReadOnlyDictionary接口(虽然有些成员明确地说),但由于某种原因我无法将实例强制转换为该接口 – 这是为什么?
IDictionary<int,string> a = new ConcurrentDictionary<int,string>(); // works
IReadOnlyDictionary<int,string> b = new ConcurrentDictionary<int,string>(); // does not work

.. 这是为什么?

为了使这一点更清楚:

解决方法

您可能使用.NET版本,其中此接口未由 ConcurrentDictionary实现.从我尝试过的版本不是由4.6之前的.NET版本实现的:
[SerializableAttribute]
[ComVisibleAttribute(false)]
[HostProtectionAttribute(SecurityAction.LinkDemand,Synchronization = true,ExternalThreading = true)]
public class ConcurrentDictionary<TKey,TValue> : IDictionary<TKey,TValue>,ICollection<keyvaluePair<TKey,TValue>>,IEnumerable<keyvaluePair<TKey,IDictionary,ICollection,IEnumerable

在当前的.NET框架版本(4.6.2)中,ConcurrentDictionary实现了它:

[SerializableAttribute]
[ComVisibleAttribute(false)]
[HostProtectionAttribute(SecurityAction.LinkDemand, TValue>, TValue>>,IEnumerable,IReadOnlyDictionary<TKey,IReadOnlyCollection<keyvaluePair<TKey, TValue>>

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...