ConcurrentDictionary和IDictionary [英] ConcurrentDictionary and IDictionary

查看:180
本文介绍了ConcurrentDictionary和IDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到ConcurrentDictionary实现了IDictionary接口,尽管接口支持Add,ConcurrentDictionary没有该函数。这个怎么用?我认为接口强加了实现类的功能...

I noticed that ConcurrentDictionary implements the IDictionary interface, yet despite that the interface supports Add, ConcurrentDictionary doesn't have that function. How does this work? I thought interfaces imposed functionality on the implementing classes...

推荐答案

它使用显式接口实现。这是一个例子。

It is using explicit interface implementation. Here is an example.

interface IFoo
{
   void Foo();
}

class FooImplementation : IFoo
{
   void IFoo.Foo()
   {
   }
}

如果您将 ConcurrentDictionary $ c> IDictionary ,可以使用所有定义的方法。

If you assign or cast a ConcurrentDictionary to IDictionary, you can use all the methods defined there.

这篇关于ConcurrentDictionary和IDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆