检查字典中是否存在密钥 [英] checking if key exists in dictionary

查看:80
本文介绍了检查字典中是否存在密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何检查字典中是否存在键?

How do you check to see if a key exists in a Dictionary?

推荐答案

您可以判断字典中是否包含键,因为它会赢得键.除非这是个很小的钥匙,否则不能正确关闭.

坦白地说,您花费的时间比看自己要花费的时间更多. 文档 [
You can tell if a dictionary has a key in it because it won''t close properly, unless it''s a really small key.

Honestly, you spent more time typing that message than it would have taken to just look yourself. Documentation[^] It''s not just there for fun.


只需使用 ContainsKey方法 [
Just use ContainsKey Method[^] to check a key existence in the dictionary.


除了Wonde建议的那样:您还可以使用System.Collections.Generic.Dictionary.TryGetValue,请参见 http://msdn.microsoft.com/en-us/library/bb347013.aspx [ ^ ].

要确认SK Genius所说的话,您输入该信息所花的时间将比仅仅看自己要花费更多的时间.

—SA
In addition to what Wonde advised: you can also use System.Collections.Generic.Dictionary.TryGetValue, see http://msdn.microsoft.com/en-us/library/bb347013.aspx[^].

To confirm what SK Genius say, you would spent more time typing that message than it would have taken to just look yourself.

—SA


这篇关于检查字典中是否存在密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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