Dictionary.TryGetValue 方法
2010-12-17 14:26
337 查看
public bool TryGetValue ( TKey key, out TValue value )参数
key 要获取的值的键。 value 当此方法返回值时,如果找到该键,便会返回与指定的键相关联的值;否则,则会返回 value 参数的类型默认值。该参数未经初始化即被传递。返回值
如果 Dictionary 包含具有指定键的元素,则为 true;否则为 false。
string value = ""; if (openWith.TryGetValue("tif", out value)) { Console.WriteLine("For key = /"tif/", value = {0}.", value); } else { Console.WriteLine("Key = /"tif/" is not found."); } ... // The indexer throws an exception if the requested key is // not in the dictionary. try { Console.WriteLine("For key = /"tif/", value = {0}.", openWith["tif"]); } catch (KeyNotFoundException) { Console.WriteLine("Key = /"tif/" is not found."); }
相关文章推荐
- Dictionary.TryGetValue 方法 试用记 Mark
- 二十六、详测 Generics Collections TDictionary(2): ContainsKey、ContainsValue、AddOrSetValue、TryGetValue
- Dictionary 快速查找---TryGetValue(string key,out string value)
- 详测 Generics Collections TDictionary(2): ContainsKey、ContainsValue、AddOrSetValue、TryGetValue
- GetItemValue、Itemname使用方法
- document.getElementById("").style和$("").css(name,value)方法的区别?
- 按索引index取出指定位置泛型字典Dictionary的key和value的方法举例
- 使用GetValueSource方法获取依赖属性的源
- python 利用dictionary的get( ) 方法做计数统计
- 调用js报错:try { document.getElementById("").SetReturnValue(__flash__toXML(MY_FUNCTION(
- Selenium获取input值的两种方法:WebElement.getAttribute("value")和WebElement.getText()
- 异常捕捉先后顺序------getCustomerInfo()方法如下,try中可以捕获三种类型的异常,如果在该方法运行中产生了一个IOException,将会输出什么结果()
- 关于Dictionary的TryGetValue方法
- python字典(dictionary)中get和items、iteritems方法
- configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));错误解决方法
- 14. 59. 6.JTable添加逻辑值的方法 Add logic to get value method
- configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));错误解决方法
- js小练习:利用getElementsByTagName方法、for循环、this指针、数组实现对多个相同元素value值的改变
- Python 字典(Dictionary) get()方法
- Python 字典(Dictionary) get()方法