How fast is operation on KeyCollection returned by Dictionary.Keys ? (.NET)

偶尔善良 提交于 2019-12-04 17:14:13

Since IDictionary<K,V> is only an interface, not an implementation, then it doesn't provide any performance guarantees.

For the built-in Dictionary<K,V> type, the ContainsKey method should be O(1):

This method approaches an O(1) operation.

The Keys.Contains method actually calls the parent dictionary's ContainsKey method, so that should also be O(1):

This method is an O(1) operation.

(Both quotes are taken from the "Remarks" section of the relevant documentation pages.)

The first link you provided says, in the Remarks:

This method approaches an O(1) operation.

Also, if you click on the Contains method you'll see the same thing in the remarks:

This method is an O(1) operation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!