且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是什么字典之间的差异(字符串,字符串)和IDictionary的(字符串,字符串)

更新时间:2022-06-22 05:39:49

IDictionary的只是一个接口 - 它描述了实现类必须做什么合同。字典是实现该接口,因此必须提供IDictionary接口描述的方法的具体类。

IDictionary is only an interface - a contract which describes what an implementing class must do. Dictionary is a concrete class that implements that interface and hence must provide the methods described in the IDictionary interface.

如果你想创建你必须创建一个具体的类(即词典)一本字典,但如果你想与字典做的是IDictionary接口暴露的方法,你可以通过concreate类圆形作为一个接口 - 这减少的方法之间的耦合。

If you want to create a dictionary you must create a concrete class (i.e. Dictionary), but if all you want to do with that dictionary is methods exposed by the IDictionary interface you can pass the concreate class round as an interface - which reduces the coupling between methods.