IDictionary< string,string>与字典< string,string> [英] IDictionary<string, string> versus Dictionary<string, string>

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

问题描述

这里使用IDictionary的价值是什么?

what is the value of using IDictionary here?

推荐答案

使用接口的值总是相同的:you don在切换到另一个后端实现时,不得不更改客户端代码。

The value of using an interface is always the same: you don't have to change client code when switching to another backend implementation.

考虑分析你的代码后来显示一个哈希表实现(在 Dictionary 类)不适合您的任务,并且二叉搜索树将表现更好。如果你已经编码到一个接口,然后切换实现是直接。然而,如果你使用了一个具体的类,你必须在更多的地方改变更多的代码。 =>这会花费时间和金钱。

Consider that profiling your code later shows that a hash table implementation (used in the Dictionary class) isn't suited for your task and that a binary search tree would perform better. If you've coded to an interface then switching the implementation is straightforward. If, however, you've used a concrete class, you've got to change a lot more code in a lot more places. => This costs time and money.

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

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